AppBarButton exception in Universal WinRT application does not trigger an unhandled exception event

I have a Universal WinRT application, and I'm trying to implement global exception handling, so I can offer the user to send me a report with additional diagnostic information that I collected. (Additional diagnostic information is why I cannot use the built-in handler that will connect to the Dev Portal).

I have the following code:

public App() { InitializeComponent(); UnhandledException += OnUnhandledException; // other stuff } private void OnUnhandledException(object sender, UnhandledExceptionEventArgs e) { try { //handler } catch { } throw e.Exception; } 

When I force an exception on my XAML start page (my login page), e. d. hard code

 throw new FileNotFoundException(); 

then my handler starts as expected. However, if I do this on my hub home page, which goes to my start page, then it looks like my handler is not starting. I see that the exception is thrown into the debugger, but they just swallow it. I can’t find out where. I must mention that the application happily continues at this stage - this is not a failure.

I set DISABLE_XAML_GENERATED_BINDING_DEBUG_OUTPUT and DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION to disable the built-in overrides, and as far as I know, there is no async void situation here (for example, I didn’t handle the event handler for Void read, such a problem is resolved in 8.1 anyway). But there may be some hidden asynchronous thing that I do not see.

I'm sure I'm missing something stupid. What is it?

(EDIT) This seems to be the problem when the exception is in the AppBarButton button AppBarButton .

(EDIT 2) Somewhat minimal playback level here: http://1drv.ms/1rSNq3i - run this in the emulator 8.1 or on the phone 8.1, click the button, open the command line and select sign out - this should cause an exception and a handler, but an exception will be lost. If you move the code to a button on the same page (standard button), the handler will start firing.

(EDIT 3) I tried to use the dispatcher minimally, and it did not change the visible result:

 private void SignOutAppBarButton_Click(object sender, RoutedEventArgs e) { Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { throw new FileNotFoundException(); }).AsTask().Wait(); } 
+5
source share
1 answer

In addition to the UnhandledException event UnhandledException you need to handle Frame.NavigationFailed . An exception in the page constructor results in a NavigationFailed firing.

0
source

Source: https://habr.com/ru/post/1204136/


All Articles