Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhandled exception crashes App, but only if originating from async method #6304

Closed
1 of 2 tasks
MrDeej opened this issue Nov 15, 2021 · 3 comments
Closed
1 of 2 tasks
Assignees
Labels
duplicate This issue or pull request already exists

Comments

@MrDeej
Copy link

MrDeej commented Nov 15, 2021

Describe the bug

If and exception occurs in an async method (button click event for example). It cannot be handled by App.UnhandledException and it will crash the app.
If and exception occurs in an void method( button click event for examp). It can be be handled by App.UnhandledException.

Steps to reproduce the bug

  1. Make a new WinUI Desktop App.
  2. Upgrade nuget to WinUI 3 Preview v3
  3. Subscribe to app unhandledexception:
public App()
        {
            this.InitializeComponent();
            this.UnhandledException += App_UnhandledException;
        }
        private void App_UnhandledException(object sender, Microsoft.UI.Xaml.UnhandledExceptionEventArgs e)
        {
            e.Handled = true;
        }
  1. Make an Additional button in the UI.
private void myButton_Click(object sender, RoutedEventArgs e)
        {
            //this is catched in app unhandled exception
            throw new Exception("void");
        }
        private async void myButton1_Click(object sender, RoutedEventArgs e)
        {
            //this crashes app
            throw new Exception("Async void");
        }

Expected behavior

Both async and void method should route exception to UnhandledException in app.

Should never ever ever crash an app due to an unhandled exception. This makes a horrid user experience.

Screenshots

No response

NuGet package version

No response

Windows app type

  • UWP
  • Win32

Device form factor

Desktop

Windows version

May 2021 Update (19043)

Additional context

No response

@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label Nov 15, 2021
@kmgallahan
Copy link
Contributor

Related #6153

@StephenLPeters StephenLPeters added duplicate This issue or pull request already exists and removed needs-triage Issue needs to be triaged by the area owners labels Feb 11, 2022
@Scottj1s Scottj1s self-assigned this Jun 15, 2022
@Scottj1s
Copy link
Member

This is more closely a duplicate of #5221

@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label Jun 25, 2022
@sjb-sjb
Copy link

sjb-sjb commented Jun 25, 2022

Here's another version, and as minimal as one can imagine. Use the "Blank App, Packaged (WinUI 3 in Desktop)" template with the Visual Studio configuration copied below. Edit the OnLaunched method in App.xaml.cs as follows:

protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
{
    this.UnhandledException += this.App_UnhandledException;
    throw new InvalidOperationException("test");
    //m_window = new MainWindow();
    //m_window.Activate();
}

private void App_UnhandledException(object sender, Microsoft.UI.Xaml.UnhandledExceptionEventArgs e)
{
    System.Diagnostics.Debug.WriteLine("tested");
}

Expected: App_UnhandledException is invoked.

Actual: App_UnhandledException is not invoked, and the program crashes with the message "An unhandled Win32 exception occurred in [15028] Test.exe" in a window that asks you to attach a debugger.

--
Microsoft Visual Studio Community 2022
Version 17.2.0
VisualStudio.17.Release/17.2.0+32505.173
Microsoft .NET Framework
Version 4.8.04084

Installed Version: Community

Visual C++ 2022 00482-90000-00000-AA995
Microsoft Visual C++ 2022

ASP.NET and Web Tools 2019 17.2.388.21846
ASP.NET and Web Tools 2019

Azure App Service Tools v3.0.0 17.2.388.21846
Azure App Service Tools v3.0.0

C# Tools 4.2.0-4.22252.24+47cdc16a21bbb8a4aadfb666b011e2059e1be5d2
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools 1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Microsoft JVM Debugger 1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

NuGet Package Manager 6.2.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

TypeScript Tools 17.0.10418.2001
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools 4.2.0-4.22252.24+47cdc16a21bbb8a4aadfb666b011e2059e1be5d2
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools 17.1.0-beta.22178.3+6da0245a7ce4bb8483b8d1f2993c8ecaea967ad9
Microsoft Visual F# Tools

Visual Studio IntelliCode 2.2
AI-assisted development for Visual Studio.

@ojhad ojhad removed the needs-triage Issue needs to be triaged by the area owners label Jun 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

6 participants