ASP.NET web application allows us to you implement IHttpModule interface to catch all unhandled exception. Similar way we can catch all unhandled exceptions in winforms applications by handling AppDomain.CurrentDomain.UnhandledException event.
The main idea is to do something like this:
code source
The main idea is to do something like this:
static void Main(string[] args)
{
AppDomain.CurrentDomain.UnhandledException +=
new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
}
In the implementation of the CurrentDomain_UnhandledException method, we can write to the log, close some open handles and most important - show a pleasant message to the user.
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
try
{
// Write to the log, close handels, …
// Show message box.
}
finally
{
Application.Exit();
}
}
code source
Comments