Bug 42793 - Setting Handled = true in UnhandledException handler has no effect on WinRT 8.1
Summary: Setting Handled = true in UnhandledException handler has no effect on WinRT 8.1
Status: CONFIRMED
Alias: None
Product: Forms
Classification: Xamarin
Component: Forms ()
Version: 2.3.0
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-07-25 23:39 UTC by John Hardman
Modified: 2016-08-10 15:55 UTC (History)
3 users (show)

Tags: WinRT 8.1 WinPhone Handled UnhandledException ac
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report for Bug 42793 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
CONFIRMED

Description John Hardman 2016-07-25 23:39:10 UTC
On Windows platforms (WinRT 8.1, WinPhone RT 8.1, and UWP), I define DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION in the project properties, and then implement my own UnhandledException handler as follows:

            UnhandledException += async (sender, eo) =>
            {
                try
                {
                    eo.Handled = true;

                    Exception ex = eo.Exception as Exception;
                    if (ex != null)
                        InsightsWrapper.SilentlyReportException(ex);

                    // TODO - attempt to use localised text first, but then fallback to hardcoded text if the localised fails
                    MessageDialog md = new MessageDialog(
                        "Something went wrong with the app. Probably best to re-start it as soon as possible.",
                        "Oops!");
                    await md.ShowAsync();
                }
                catch (Exception ex)
                {
                    InsightsWrapper.ReportException(ex);
                }


Note that InsightsWrapper is just a thin wrapper around Insights/HockeyApp.

On UWP (both 32 and 64 bit builds), the above code does what I would expect, popping up the MessageDialog and waiting for the user to hit the button on the dialog.

However, on WinRT 8.1 and WinPhone RT 8.1, it seems that setting Handled on the exception object has no effect. Despite setting Handled = true, and doing the await, the application closes rather than waiting for the user to respond (and then carrying on as before).