App.UnhandledException doesn't catch exceptions from other threads.
See original GitHub issueDescribe the bug Unable to catch UnhandledException (at app level) when the exception originates from async Task.
Steps to reproduce the bug
- Create new WinUI3 project
- In App.cs handle UnhandledException:
public App()
{
this.InitializeComponent();
this.UnhandledException += App_UnhandledException;
}
private void App_UnhandledException(object sender, Microsoft.UI.Xaml.UnhandledExceptionEventArgs e)
{
Debug.WriteLine("WinUI App Crashed");
}
- In MainWindow.cs add a button with code-behind that will throw a devide-by-zero exception from an Async method:
private async void myButton_Click(object sender, RoutedEventArgs e)
{
int t = await Task.Run(() =>
{
var x = 0;
var y = 3 / x;
return y;
});
}
Expected behavior Would expect the App_UnhandledException to ‘handle’ this exception.
Screenshots
Version Info WinUI 0.8.0-preview Windows 10
NuGet package version: Microsoft.ProjectReunion (0.8.0-preview) Microsoft.ProjectReunion.Foundation (0.8.0-preview) Microsoft.ProjectReunion.WinUI (0.8.0-preview)
Windows app type:
UWP | Win32 |
---|---|
No | Yes |
Windows 10 version | Saw the problem? |
---|---|
Insider Build (xxxxx) | |
October 2020 Update (19042) | Yes |
May 2020 Update (19041) | |
November 2019 Update (18363) | |
May 2019 Update (18362) | |
October 2018 Update (17763) | |
April 2018 Update (17134) | |
Fall Creators Update (16299) | |
Creators Update (15063) |
Device form factor | Saw the problem? |
---|---|
Desktop | Yes |
Xbox | |
Surface Hub | |
IoT |
Additional context GitHub example with 2 ‘identical’ projects, one UWP (WinUI2) and one WinUI3, to show the difference in behavior between the two. https://github.com/artkat/CrashingApp
Issue Analytics
- State:
- Created 2 years ago
- Reactions:6
- Comments:31 (12 by maintainers)
Top Results From Across the Web
c# - Catching unhandled exception on separate threads
I am using the following event to catch unhandled exceptions in the main UI thread. ... However, this seems to shut down the...
Read more >Exceptions in Managed Threads
See how unhandled exceptions are handled in .NET. Most unhandled thread exceptions proceed naturally and lead to application termination.
Read more >Application.ThreadException Event (System.Windows.Forms)
To catch exceptions that occur in threads not created and owned by Windows Forms, use the UnhandledException event handler. To guarantee that no...
Read more >Unhandled exceptions terminate the thread (not the process)
If an unhandled exception condition happens in a secondary thread and moves all the way to the first invocation in the thread without...
Read more >15.3. Preventing Silent Thread Termination - C# Cookbook ...
An unhandled exception in a spawned worker thread, however, will terminate only that thread. This will happen without any visible warnings, and your...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This bug has been reported nearly a year ago. Still, no one has been assigned to fix it. I’m disappointed, frustrated, annoyed, and honestly quite pissed that this is the way Microsoft handles this project.
App.UnhandledException fix will be available in Windows App SDK 1.2 Preview 2