Created
January 17, 2022 13:37
-
-
Save RachidAZ/846e4006d9293841dc62d57de6c688c9 to your computer and use it in GitHub Desktop.
Catch unhandled exceptions in C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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