dotnet / dotnet/dotnet-api-docs
Application.ThreadException Event example doesn't follow AppDomain.UnhandledException text
- Dominant language
- C#
- Stars
- 949
- Forks
- 1.7k
- Avg merge
- 3d 27m
- Merged PRs (30d)
- 49
Description
Hi,
On page
[system.appdomain.unhandledexception](https://docs.microsoft.com/en-us/dotnet/api/system.appdomain.unhandledexception)
It states that
`This behavior can be changed by using the application configuration file, or by using the Application.SetUnhandledExceptionMode method to change the mode to UnhandledExceptionMode.ThrowException before the ThreadException event handler is hooked up.`
The relevant part - "SetUnhandledExceptionMode **before** the ThreadException event handler is hooked up"
However on page
[system.windows.forms.application.threadexception](https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.application.threadexception)
The example shows SetUnhandledExceptionMode **after** the ThreadException is hooked up.
```
public static void Main(string[] args)
{
// Add the event handler for handling UI thread exceptions to the event.
Application.ThreadException += new ThreadExceptionEventHandler(ErrorHandlerForm.Form1_UIThreadException);
// Set the unhandled exception mode to force all Windows Forms errors to go through
// our handler.
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
// Add the event handler for handling non-UI thread exceptions to the event.
AppDomain.CurrentDomain.UnhandledException +=
new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
// Runs the application.
Application.Run(new ErrorHandlerForm());
}
```
thanks
Mike
Contributor guide
Assessment
This issue has not been assessed yet.