Skip to content

Instantly share code, notes, and snippets.

@RachidAZ
Created January 17, 2022 13:37
Show Gist options
  • Save RachidAZ/846e4006d9293841dc62d57de6c688c9 to your computer and use it in GitHub Desktop.
Save RachidAZ/846e4006d9293841dc62d57de6c688c9 to your computer and use it in GitHub Desktop.
Catch unhandled exceptions in C#
using System;
private static void SetGlobalExceptionHandler()
{
AppDomain currentDomaine = AppDomain.CurrentDomain;
currentDomaine.UnhandledException += new UnhandledExceptionEventHandler(Handler);
}
private static void Handler(object sender, UnhandledExceptionEventArgs e)
{
Console.WriteLine("Unhandled exception : " + ((Exception) e.ExceptionObject).Message);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment