How do I implement a global exception handler?
How do I implement a global exception handler?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Andrew FensterPosted May 13, 2011, 5:30 PM
ELMAH is for ASP.Net. Are you talking about an ASP.Net application, or something else?
In ASP.Net you can catch exceptions in the Global.asax file as follows. (Written in VB.Net)
Sub Application_Error(ByVal sender As Object, ByVal e As EventArgs)
Try
Dim ex As Exception = HttpContext.Current.Server.GetLastError()
'Code to log error goes here.
HttpContext.Current.Server.ClearError()
'Code to redirect user to error page goes here.
Catch ex As Exception
'DO NOTHING ... do not want to have infinite loop
End Try
End Sub
This code will catch and process all exceptions which weren't caught at some earlier stage.
Guest UserPosted May 13, 2011, 8:43 AM