UnhandledExceptionMode Enumeration
Defines where a Windows Forms application should send unhandled exceptions.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
| Member name | Description | |
|---|---|---|
| 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.
Note |
|---|
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.
Available since 2.0
