Global Error Handling

  • Thread starter Thread starter Jim Slade
  • Start date Start date
J

Jim Slade

I'd like to be able to log each error that occurs in an ASP.NET application.
Do I really need to have a try/catch block in every single one of my
methods? Is there a way to somehow handle ALL errors without having a
bazillion try/catch blocks?

Thanks!
 
Couple different routes to go.

Override the Application_Error method in Global.asax.cs. You can use
Server.GetLastError() to get the last exception chain that occurred. After
"handling" (logging) the error, you will need to call Server.ClearError() to
redirect your user to another page.

You can derive your own base page and override the OnError method to capture
all errors that occurred on the page. This enables you to track more detail
on exactly what was happening on the page that caused the error. ie Get
Request.Form variables, Session.

I am sure you can get all this information from the Global error hanlder,
but it seemed more natural for my group to actually implement both methods.
The Page.Error event will not capture some of the exceptions that might
occur during application running, such as application start, etc.

HTH,

bill
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top