Fetch unhandled exceptions in C#
using System; namespace SomeNamespace { [STAThread] static class Program { private static void Main() { // Trace all unhandled exceptions AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(Program.OnUnhandledException); } } ///<summary> /// Event handler for unhandled exceptions ///</summary> private static void OnUnhandledException(object sender, UnhandledExceptionEventArgs e) { Exception exceptionObject = e.ExceptionObject as Exception; // Do something with the unhandled exception here } }
Registers an event handler for all unhandled exceptions that are thrown during runtime.
Most popular snippets