Skip to content

Throwing FooException makes AppDomain throw JavaProxyThrowable instead of FooException #1144

Closed

Description

@knocte

Steps to Reproduce

  1. Create new XamarinForms project (template from VSforMac for example).
  2. Create class FooException : Exception.
  3. Hook into AppDomain.CurrentDomain.UnhandledException with a method Bar(sender, args) that receives the exception in the args.ExceptionObject property.
  4. Make the AppPage of the app throw this new FooException.
  5. Run the app in iOS: exception received is of type FooException.
  6. Run the app in Android.

Expected Behavior

Exception received by the Bar() method is of type FooException (or at least contains the FooException in the InnerException chain?)

Actual Behavior

Exception received by the Bar() method is of type JavaProxyThrowable, and its message is "Exception of type 'Android.Runtime.JavaProxyThrowable' was thrown". The only bit of "FooException" found in this exception object is in the stack trace, however this is not an acceptable way for the callers to find what exception was really thrown, especially because it would need to be platform-specific code (only Android exhibits this behaviour, other platforms don't).

Version Information

Visual Studio Community 2017 for Mac
Version 7.3.2 (build 12)
Installation UUID: fd06ff65-69de-47ae-8b99-ddf257032b7c
Runtime:
Mono 5.4.1.7 (2017-06/e66d9abbb27) (64-bit)
GTK+ 2.24.23 (Raleigh theme)

Package version: 504010007

NuGet
Version: 4.3.1.4445

.NET Core
Runtime: /usr/local/share/dotnet/dotnet
Runtime Version: 2.0.0
SDK: /usr/local/share/dotnet/sdk/2.0.0/Sdks
SDK Version: 2.0.0
MSBuild SDKs: /Library/Frameworks/Mono.framework/Versions/5.4.1/lib/mono/msbuild/15.0/bin/Sdks

Xamarin.Profiler
Version: 1.6.0
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

Xamarin.Android
Version: 8.1.0.25 (Visual Studio Community)
Android SDK: /Users/andres/Library/Developer/Xamarin/android-sdk-macosx
Supported Android versions:
7.1 (API level 25)

SDK Tools Version: 26.1.1
SDK Platform Tools Version: 26.0.2
SDK Build Tools Version: 26.0.3

Java SDK: /usr
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

Apple Developer Tools
Xcode 9.2 (13772)
Build 9C40b

Log File

(I don't believe there's need for a log file)

Activity

  1. jonpryor commented on Jan 2, 2018

    @jonpryor
    Contributor

    The problem is that we don't "unwrap" exceptions when raising the AppDomain.UnhandledException event:

    var args  = new UnhandledExceptionEventArgs (ex, isTerminating: true);
    AppDomain_DoUnhandledException (AppDomain.CurrentDomain, args);

    ex will be a Java.Lang.Throwable instance, e.g. JavaProxyThrowable, which explains the described behavior.

  2. added
    Area: App Runtime
    on Jan 2, 2018
  3. knocte commented on Jan 5, 2018

    @knocte
    ContributorAuthor

    Wow guys that was fast! Thank you, and happy new year.

    By the way, am new to XamarinAndroid, so how will I be able to get this bugfix? Through nuget or through VS4Mac update? (And is there anyway to know the version number I should be looking for...?)

    Thanks!

  4. jonpryor commented on Jan 5, 2018

    @jonpryor
    Contributor

    @knocte asked:

    how will I be able to get this bugfix?

    That depends on whether you need a "proper" commercial installer, or if you can use just the OSS bits. The fix is only on master at present, and thus won't be released commercially until "d15-7"/Xamarin.Android 8.3. (Release date unknown.)

    If you can you the OSS builds, you can follow the steps within Documentation/UsingJenkinsBuildArtifacts.md and grab one of the files from Jenkins, e.g.

  5. added a commit that references this issue on Jan 23, 2021
  6. ghost locked as resolved and limited conversation to collaborators on Jun 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Area: App Runtime

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions