App.UnhandledException doesn't work at all
See original GitHub issueDescribe the bug
Hi, how can I show the message when an application was crashed? The App.UnhandledException event doesn’t work. I’ve attached the sample. Also, I’ve found the issue https://github.com/microsoft/microsoft-ui-xaml/issues/5221 but in my case, it doesn’t catch any exceptions from the main thread. Same issue on WindowsAppSDK 1.0 preview 2
Steps to reproduce the bug
App.xaml.cs
public partial class App : Application {
public App() {
UnhandledException += App_UnhandledException;
this.InitializeComponent();
}
async void App_UnhandledException(object sender, Microsoft.UI.Xaml.UnhandledExceptionEventArgs e) {
var dialog = new Windows.UI.Popups.MessageDialog(e.Exception.ToString());
await dialog.ShowAsync();
}
protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args) {
m_window = new MainWindow();
m_window.Activate();
}
private Window m_window;
}
MainWindow.xaml.cs
public sealed partial class MainWindow : Window {
public MainWindow() {
this.InitializeComponent();
}
void myButton_Click(object sender, RoutedEventArgs e) {
throw new ArgumentException("test");
}
}
Expected behavior
No response
Screenshots
https://i.imgur.com/WnHKKnV.gif
NuGet package version
WinUI 3 - Windows App SDK 0.8: 0.8.0 (If you’re seeing your issue in older previews of WinUI 3, please try this release)
Windows app type
- UWP
- Win32
Device form factor
Desktop
Windows version
May 2020 Update (19041)
Additional context
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
UnhandledException Event doesn't work?
I'm writing a little library which catches all unhandled exceptions, shows a little dialog (similar to the usual dialog of the NF) which...
Read more >Application.UnhandledException Event (Windows.UI.Xaml)
Occurs when an exception can be handled by app code, as forwarded from a native-level Windows Runtime error. Apps can mark the occurrence...
Read more >c# - How to treat unhandled exceptions? (Terminate the ...
In my experience many users don't take any notice but just tap in the app icon again. Obviously you need to make sure...
Read more >Exceptions cause ASP.NET apps to quit
This article describes a problem that occurs when an unhandled exception is thrown in an ASP.NET-based application on a computer that is ...
Read more >Console apps and AppDomain.CurrentDomain. ...
The unhandled exception handler works properly for winforms apps. Slightly different handler, though: Application.ThreadException. You only have ...
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
App.UnhandledException fix will be available in Windows App SDK 1.2 Preview 2
That doesn’t sound correct 🤔 A UWP app would catch the majority of CLR and WinRT errors in the above in the App.UnhandledException handler no problem ignoring exceptions thrown in Tasks (in fact, I’ve just tried the above and it works as expected in UWP), and Frame navigation failures would probably bubble up Frame.NavigationFailed event. I would expect WinUI to behave similarly?