Last one, how many of you guys are using this rather than the on error goto statement in your aspx pages?
What's the general preference of this one, as a rule, when are you meant to use it?
Thanks! :D
Printable View
Last one, how many of you guys are using this rather than the on error goto statement in your aspx pages?
What's the general preference of this one, as a rule, when are you meant to use it?
Thanks! :D
I am using this Try...Catch...End Try as it is more structured.
<raises hand>
Easier to handle errors when they need to be handled without jumping around. Considering most every other language uses TRy catch...you should not use on error anymore. Besdies, the Exception object is so much cooler anway.
Cool tip:
Catch ex As Exception
Dim errorlocation As String = ex.TargetSite.Name
errorlocation will return the sub/function name where the error occurs. Very handy. using this can demonstrate another reason why try catch is better. build a try catch in one sub..Call another sub with no error handler and raise an error.
ie:
Error 91
then use that code up above in the Catch statement for the orginal sub. Even though the error happens in the called sub, the orginal sub will catch the error and the errorlocation string will still return the name of the sub where the error really happened.
I use the Try..Catch...Finally structure, works a treat, especially useful in pages doing data acces (ie just about every .aspx known to man!!).
I particularly like being able to nest them, it's just so much better than the old on error... statement.
A nice feature of Try...Catch is Catch When, e.g.
Catch When Err.Description = "Some error string for a non-numbered exception that you know exactly what the description will be and would like specific code executed for that error"
Catch When Err.Number = 5