Search code examples
asp.netexceptionerror-handlingapplication-error

Throwing all errors to be handled in Application_Error handler in Global.asax


I want to throw all the form errors to the event log. To achieve this, I added code to Application_Error handler to send the error text to event log. I would like to know how to throw the exception to be caught in the Application_Handler without disrupting the normal flow of the page lifecycle.

I tried simply throwing ApplicationException:

throw new ApplicationException(String.Format("Http Request failed. {0}", userStatusErrorMessage));

It worked in the sense that the error details was added to the event log, but the page that threw the exception was not displaying anything after throwing the error. It was blank.

Any ideas? Much appreciated. Thank you and happy weekend!


Solution

  • Handling exceptions in global.asax would mean that you cannot go on " without disrupting the normal flow of the page lifecycle". That approach makes sense when you want to log the exception and then redirect to the configured custom error-page.

    If you only want to log the exception and then act as if nothing had happened, you must catch the exception and call your logging method there. But i would suggest against it because an exception should be visible for the user.