OnUnhandledException method is added to the AppDomain.UnhandledException event
using System;
public class Starter {
public static void Main() {
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(OnUnhandledException);
int vara = 5, varb = 0;
vara /= varb;
}
public static void OnUnhandledException(
object sender, UnhandledExceptionEventArgs e) {
string application_name = sender.ToString();
Exception except = (Exception)e.ExceptionObject;
string errormessage = "Application " + application_name +
" [ Exception " + except.Message + " ]";
Console.WriteLine(errormessage);
}
}
Related examples in the same category