UnhandledExceptionMode Enumeration

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Defines where a Windows Forms application should send unhandled exceptions.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

type UnhandledExceptionMode

Member nameDescription
Automatic

Route all exceptions to the ThreadException handler, unless the application's configuration file specifies otherwise.

CatchException

Always route exceptions to the ThreadException handler. Ignore the application configuration file.

ThrowException

Never route exceptions to the ThreadException handler. Ignore the application configuration file.

This enumeration is used by SetUnhandledExceptionMode.

System_CAPS_noteNote

In the .NET Framework version 2.0, the common language runtime behavior changed to allow unhandled exceptions to propagate up the call stack. This behavior can be disabled via the application configuration file. For more information, see Exceptions in Managed Threads.

The following code example sets event handlers for both errors that occur on Windows Forms threads and errors that occur on other threads. It sets SetUnhandledExceptionMode so that all errors are handled by the application, regardless of the settings in the application's user configuration file. It uses the ThreadException event for the former, and the UnhandledException event for the latter. Since UnhandledException cannot prevent an application from terminating, the example simply logs the error in the system Event Log prior to termination.

This sample assumes that you have defined two Button controls, button1 and button2, on your Form class.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 2.0
Return to top
Show: