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 (show other bugs)
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)

See Also:
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

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....

Note You need to log in before you can comment on or make changes to this bug.