question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

App.UnhandledException doesn't work at all

See original GitHub issue

Describe 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

App3.zip

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Scottj1scommented, Sep 6, 2022

App.UnhandledException fix will be available in Windows App SDK 1.2 Preview 2

1reaction
JohnnyWestlakecommented, Oct 26, 2021

UnhandledException is a bit of a misnomer… It is actually only thrown when something in the framework raises an error during Frame.Navigate, the name is quite bad but this is expected behavior.

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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found