In Global.asax, if you use one that is automatically created by Visual Studio, you can add code to the Application_Error method to handle exceptions and register them in any way. You can also override the Init method and add an event handler for the class error event.
In any case, you only get the useless vanilla EventAgs object, but you can use HttpContext.Current.Server.GetLastError () to get the exception that raised.
As another poster is mentioned, this may not catch exceptions that are triggered by asynchronously running delegates, threads that you run yourself, or asynchronous page tasks created using Page.RegisterAsyncTask (). In this case, you always need to make sure that implementations have exceptions with return stops, so that exceptions can be detected and the IIS workflow will not be interrupted.
source share