Export (0) Print
Expand All
Expand Minimize

UnhandledExceptionMode Enumeration

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
AutomaticRoute all exceptions to the ThreadException handler, unless the application's configuration file specifies otherwise.
CatchExceptionAlways route exceptions to the ThreadException handler. Ignore the application configuration file.
ThrowExceptionNever route exceptions to the ThreadException handler. Ignore the application configuration file.

This enumeration is used by SetUnhandledExceptionMode.

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

Supported in: 4.6, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft