Bug 56102 - Try/Catch not working as expected on initial load of activity
Summary: Try/Catch not working as expected on initial load of activity
Alias: None
Product: Android
Classification: Xamarin
Component: General ()
Version: 7.3 (15.2)
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Jonathan Pryor
Depends on:
Reported: 2017-05-08 15:38 UTC by JohnRowse
Modified: 2018-02-10 22:57 UTC (History)
2 users (show)

Tags: bb ac
Is this bug a regression?: ---
Last known good build:

Test Project to recreate (27.27 KB, application/x-zip-compressed)
2017-05-08 15:38 UTC, JohnRowse

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 56102 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:

Description JohnRowse 2017-05-08 15:38:52 UTC
Created attachment 22005 [details]
Test Project to recreate

If you successfully load/create an activity, any subsequent unhandled exception is confined only to that activity – you get a stopped working dialog, but the previous activity(s) remain functional. However if you put an unhandled exception in the create method of an activity, and handle the exception form the calling activity (from the StartActivity method, not only does it crash the called activity, but it crashes the calling activity. In the example, trying to load activity three, should remain on activity 2, as activity 2 is handling the load of activity 3 with a try/catch, however it returns to activity 1. The ‘crash’ button is just there to confirm the normal operation of an unhandled operation from a fully loaded activity.
Comment 1 Mark McLemore 2017-06-27 21:47:08 UTC
Confirmed with the following steps using Visual Studio 2017 15.2 and Xamarin.Android

1. Build and run the attached project.
2. In the Activity 1 screen, tap LOAD ACTIVITY 2.
3. In the Activity 2 screen, tap LOAD ACTIVITY 3.

The last step causes "Unfortunately, ActivityCrashTest has stopped" (Nexus 5, Android 6.0.1).

Here's the relevant snippet from Activity2 OnCreate:


private void LoadActivity3()

  //Handle loading an activity, that is at high risk of crashing - activity 3 will have forced exception raised during load.

      Intent intent = new Intent(this, typeof(actActivity3));
  catch (Exception)

  //NEVER REACHED!! despite exception handled.  Crashes this activity, as well as called activity (activity 3).


And here's the Activity3 OnCreate:


protected override void OnCreate(Bundle savedInstanceState)
  //Crash the activiy, before it loads


Activity1 continues to run, so you can repeat steps 2, 3 above.
Comment 2 JohnRowse 2018-02-10 22:57:24 UTC
IS anyone actually doing anything with these reports?  We take the efforts to demo the bug, it gets confirmed, nine months later, and still nothing....