I'm trying to design the exception handling mechanism in my web app, and got into some difficulties in the design.
As much as I know - there are three ways to catch exceptions in ASP.NET app -
- In the code itself (
try
,catch
,finally
) - In the
Page_Error
event of the page - In the
Application_Error
event of theglobal.asax
page
Since I have many events and functions in my .aspx pages, I wanted one single place that will catch and collect exceptions.
In other words- I really don't feel like spreaindg try-catch statments all over the code, so I thought using the Page_Error
event (which I read might be good practice at some cases).
However, a problem arises because all I want the exception handler to do is to show a nice alert on the page itself informing about general problem that took place, but as you probably know - when you get to Page_Error
the page is already dead and failed to render.
So, what other generic way is there to catch exceptions, in a manner that when I will write functions in the future I won't need to think about exceptions or try-catch, but instead know that there is a mechanism somewhere out there that will catch everything and handle it?