asp.net C# catch/try (newbie)

  • Thread starter Thread starter Rob
  • Start date Start date
R

Rob

Hey, I'm relatively new to C# and ASP.NET, but have been doing OK.

I'm trying to understand why I can't do this kind of thing to execute a
function if and only if it's defined. Is there another way to do that?

try {
FormPostBack();
}
catch { }

Many thanks,

Rob
 
Rob said:
I'm trying to understand why I can't do this kind of thing to execute a
function if and only if it's defined.

Because try..catch catches runtime errors. Calling undefined functions
results in a compile time error.
Is there another way to do that?

There are a couple things that come to mind, depending on what you want to
accomplish. The closest thing to what you are asking for is probably the
conditional attribute:

http://msdn.microsoft.com/library/en-us/csspec/html/vclrfcsharpspec_17_4_2.asp

However, if your reasons for wanting this have to do with designing reusable
code, there's probably a beter way to do it, and you should take a close
look at the capabilities of virtual methods, delegates and events.
 
Thanks for the help. I'll see what I can find.

Chris said:
Because try..catch catches runtime errors. Calling undefined functions
results in a compile time error.




There are a couple things that come to mind, depending on what you want to
accomplish. The closest thing to what you are asking for is probably the
conditional attribute:

http://msdn.microsoft.com/library/en-us/csspec/html/vclrfcsharpspec_17_4_2.asp

However, if your reasons for wanting this have to do with designing reusable
code, there's probably a beter way to do it, and you should take a close
look at the capabilities of virtual methods, delegates and events.
 
Back
Top