Is there any possibility/code other than using try...catch block for exception handling and further logging. We are developing a Web application with couple of screen. Client asked us to not to put try...catch blocks in each functions/methods to handle errors. Please suggest.
Thanks
We are developing a Web application with couple of screen
Although the requirement of you client does not make much sense for me but you can handle the unhandled exception using Application_Error event in global.asax
void Application_Error(object sender, EventArgs e)
{
//Your logging code goes here
}
How to: Handle Application-Level Errors
This code example shows how to create an error handler in the Global.asax file that will catch all unhandled ASP.NET errors while processing a request — in other words, all the errors that are not caught with a Try/Catch block or in a page-level error handler. In the example, the handler transfers control to a generic error page named GenericErrorPage.aspx, which interprets the error and displays an appropriate message.
As a additional Note for Desktop application like WinForms or Window Services you can using AppDomain.CurrentDomain.UnhandledException or Application.ThreadException etc.
You can use Application_Error in global.asax, This method handles the error for all the pages in the application.
for specific page for example default.aspx, you can implementing Page_Error
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