App.UnhandledException doesn't catch exception in WinUI 3. #1915
Replies: 3 comments 3 replies
-
I don't know that there's a single easy answer in a desktop app. There are many types of exceptions and many ways to register handlers in different languages and frameworks. But there is the unhandledexception API, and it should have a clearly defined & predictable behavior with regards to what it traps. It's probably most productive to look at your specific scenario. Can you describe the exception that you think it should be catching that it isn't? Ben |
Beta Was this translation helpful? Give feedback.
-
See also microsoft/microsoft-ui-xaml#5221 |
Beta Was this translation helpful? Give feedback.
-
I agree. A big bugbear for me has been pulling up strings from a resource file. I want my app to be fully internationalisable so I pull up everything at run time, either from ResourceLoader (c#) or x:Uid (XAML). The implementation of text resources is a bit fiddly to keep accurate and it is easy to make a mistake. I have written a common wrapper around the C# call to ResourceLoader with try/catch but this is not possible with XAML. If the specified string is not found in the x:Uid value and the app is being run from the development environment then the error is quietly handled and there is no visible indication of a fault. However, when the app is run as an EXE then as soon as the problem XAML is processed then the app just unloads. There is no trappable error, and the compiler does not provide a warning. I've had this several times since Win Reunion 0.5 (but most recently early March 2022 with Win App SDK 1.0) and it has cost me quite a few hours to untangle - originally I has no idea what the fault was and it was my first app development away from win forms so I rebuilt the entire app file by file in order to track it down. Of course it takes a while to even come to the conclusion that a resource fault is the culprit, it just unloads! (OK, on a separate issue I will one day learn how to perform crash dump analysis). As I write this I realise that a workaround would be to remove all x:Uid code and set everything in the .cs file, but I shouldn't need to workaround - I would expect the dev environment to be of practical help here. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Describe the Issue
Unable to catch UnhandledException in WinUI 3 app. This App.UnhandledException caught the exceptions on UWP but doesn't in the WInUI 3 app.
Code used
Expected solution
Is there any alternative available for App.UnhandledException event handler to catch the unhandled exceptions that work on WinUI 3 app.
Beta Was this translation helpful? Give feedback.
All reactions