catching all errors

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

hey all,
is there a way to catch all errors for my webform without using the
global.asax page?
thanks,
rodchar
 
is there a way to catch all errors for my webform without using the
global.asax page?

Other than surrounding all your code with try...catch, I don't think so...
 
Hello Mark,

BTW, u can handle your exceptions with System.Web.UI.Page.Error even

MR> MR>MR> Other than surrounding all your code with try...catch, I don't think
MR> so...
MR>
---
WBR,
Michael Nemtsev [C# MVP] :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
 
Hi Michael,
Can you please explain what mean?
many thanks


Michael Nemtsev said:
Hello Mark,

BTW, u can handle your exceptions with System.Web.UI.Page.Error even

MR> MR>MR> Other than surrounding all your code with try...catch, I don't think
MR> so...
MR> ---
WBR,
Michael Nemtsev [C# MVP] :: blog: http://spaces.live.com/laflour

"At times one remains faithful to a cause only because its opponents do
not cease to be insipid." (c) Friedrich Nietzsche
 
That website is TOTALLY AND ABSOLUTELY WRONG. It _WILL_ get corrected during
the next major revision (or help me god...). Well over 90% of the time you
can't handle an actual exception..all you can do is clean up...in which case
you should be using try/finallys and "usings". Your logging code should be
centralized, and the best way to do this is with Global.asax's on error ..

Handling exceptions in global.asax is the CORRECT way to do things.

As was mentioned, you can also catch errors in the page. you can do this by
overriding the OnError method.

protected override void OnError(EventArgs e)
{
...
}

if you put this in a base class and have all your pages inherit from it,
you're good to go.

More on exception hanlding in .NET:
http://codebetter.com/blogs/karlseguin/archive/2006/04/05/142355.aspx

Karl
 
That website is TOTALLY AND ABSOLUTELY WRONG. It _WILL_ get corrected
during the next major revision (or help me god...).

Glad to hear it!

For the record, I wasn't actually recommending following its contents -
quite the reverse... :-)
Well over 90% of the time you can't handle an actual exception..all you
can do is clean up...
in which case you should be using try/finallys and "usings".

I couldn't agree more...
Your logging code should be centralized, and the best way to do this is
with Global.asax's on error ..

Again, totally agreed...
 
Back
Top