Bug 33589 - Exception loading invalid storyboard can't be caught when Insights (or HockeyApp) is used.
Summary: Exception loading invalid storyboard can't be caught when Insights (or Hockey...
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll (show other bugs)
Version: XI 8.13 (C6 early alphas)
Hardware: PC Mac OS
: --- normal
Target Milestone: Future Cycle (TBD)
Assignee: Bugzilla
Depends on:
Reported: 2015-09-02 22:17 UTC by Jon Goldberger [MSFT]
Modified: 2016-01-08 16:40 UTC (History)
4 users (show)

See Also:
Is this bug a regression?: ---
Last known good build:

Test Project (23.23 KB, application/zip)
2015-09-02 22:17 UTC, Jon Goldberger [MSFT]

Description Jon Goldberger [MSFT] 2015-09-02 22:17:19 UTC
Created attachment 12728 [details]
Test Project

## Description

Without Xamarin Insights (or HockeyApp) being used, the following code will catch an exception from loading an invalid storyboard:

>try {
>     UIStoryboard.FromName ("Invalid-name", null);
>} catch(Exception ex) {
>     Console.WriteLine ("Exception: {0}\n{1}", ex.Message, ex.StackTrace);

However when Insights (or HockeyApp) is initialized no exception is caught and the app just crashes with an expected exception of storyboard not being found.

## Steps to reproduce

1. Open the attached test project and restore packages

2. In Main.cs, replace "YourInsightsAPIKey" with your actual Isights API Key

3. Deploy to an iOS device

Expected result: Exception about the invalid storyboard name will be caught.

Actual result: Exception is not caught and app crashes. Also the crash report is _not_ sent to Insights. 

## Notes

I see this behavior with XI 8.10 and XI 8.13. Note that if you comment out the Insights code in Main.cs, then the exception is caught as expected. 

Also it is noted that both Insights and HockeyApp use PLCrashReporter so the issue _may_ be there. 

In addition the exception is not even sent to Insights (not sure about HockeyApp but I expect it is the same). 

I did send this issue to the Insights team at first, but they said it did not seem to be an Insights issue. The reporting customer had asked:
"I would appreciate details of what goes on internally with UIStoryboard.FromName and how it creates the exception such that it is ignored by try/catch block when HockeyApp [or Insights] is enabled."

## My Environment

=== Xamarin Studio ===

Version 5.10 (build 704)
Installation UUID: 964c531b-d928-456b-a9ae-e1f82266b360
	Mono 4.2.0 (explicit/2701b19)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 402000207

=== Xamarin.Profiler ===

Not Installed

=== Apple Developer Tools ===

Xcode 6.4 (7720)
Build 6E35b

=== Xamarin.Mac ===

Version: (Business Edition)

=== Xamarin.Android ===

Version: (Business Edition)
Android SDK: /Users/apple/Library/Developer/Xamarin/android-sdk-mac_x86
	Supported Android versions:
		4.0.3 (API level 15)
		4.1   (API level 16)
		4.2   (API level 17)
		4.3   (API level 18)
		4.4   (API level 19)
		5.0   (API level 21)
		5.1   (API level 22)

SDK Tools Version: 24.3.4
SDK Platform Tools Version: 23
SDK Build Tools Version: 23

Java SDK: /usr
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)

=== Xamarin Android Player ===

Version: 0.5.6
Location: /Applications/Xamarin Android Player.app

=== Xamarin.iOS ===

Version: (Business Edition)
Hash: 79f8535
Branch: master
Build date: 2015-08-31 15:32:33-0400

=== Build Information ===

Release ID: 510000704
Git revision: c16e63aeeaa63ea912638f958ae1547905aed4e5
Build date: 2015-08-31 15:47:00-04
Xamarin addins: a7a74af8bcc6bca9a02f34afb66025c0a3fa18cb
Build lane: monodevelop-lion-master

=== Operating System ===

Mac OS X 10.10.5
Darwin Jons-iMac.local 14.5.0 Darwin Kernel Version 14.5.0
    Wed Jul 29 02:26:53 PDT 2015
    root:xnu-2782.40.9~1/RELEASE_X86_64 x86_64
Comment 2 Rolf Bjarne Kvinge [MSFT] 2016-01-08 16:40:35 UTC
This is probably the crash reporters overriding our handler for uncaught NSExceptions, preventing Xamarin.iOS from converting those ObjC exceptions to managed exceptions.

There are two possible solutions:

1) Add/request support to the crash reporters to conditionally handle uncaught NSExceptions (or a way to restore/re-enable previous handler). This is the short-term solution.

2) Add support in Xamarin.iOS for catching ObjC exceptions on the managed<-native boundary. We have plans to implement it, but it's not on the immediate roadmap, so it will likely take quite a while.

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