On a .NET exam I encountered this question.
Which of the following can you use to catch unhandled exceptions in an application?
I know its Application_Error, But what I want to know is what are the others. By some google search I found OnError can be used to catch any errors. Still I am not sure about it. Could you tell what are the other ways to catch unhandled exception
The correct point to catch your unknown errors is the Application_Error
.
Avoid to capture the OnError on your page, and let the system transfer it to the Application_Error because there you have lost the control on the page, so what other you can do if not transfer it to some error page ? - if you try to just reload it you have the problem to be in a close loop that can cause stack overflow.
From my experience I have issue when I try to handle errors using the page OnError
and I use it only when I have to free some global memory, or something like that if an error happens on page.
To give a summary, try to catch all your errors inside a try/catch block, and give a message to your user / or just take care of this issues, but let the unknown errors to the global catcher to log it and fix it. The unknown errors is something that make you lose the real control of your program, and actually you do not know what to do because you do not have predict it - so log it and fix it for the next time
More details about the errors : How do I make a "generic error" page in my ASP.NET application so that it handles errors triggered when serving that page itself?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With