Skip to content

[CoreCLR] Propagate unhandled Java exceptions #10657

@simonrozsival

Description

@simonrozsival

Android framework version

net10.0-android (Preview)

Affected platform version

.NET 10

Description

The JNIEnv.PropagateUncaughtException implementation for CoreCLR is missing:

internal static void PropagateUncaughtException (IntPtr env, IntPtr javaThreadPtr, IntPtr javaExceptionPtr)
{
if (!JNIEnvInit.PropagateExceptions)
return;
var javaException = JavaObject.GetObject<Java.Lang.Throwable> (env, javaExceptionPtr, JniHandleOwnership.DoNotTransfer)!;
if (Debugger.IsAttached) {
AndroidRuntimeInternal.mono_unhandled_exception?.Invoke (javaException);
}
try {
var jltp = javaException as JavaProxyThrowable;
Exception? innerException = jltp?.InnerException;
Logger.Log (LogLevel.Info, "MonoDroid", "UNHANDLED EXCEPTION:");
Logger.Log (LogLevel.Info, "MonoDroid", javaException.ToString ());
if (RuntimeFeature.IsMonoRuntime) {
MonoDroidUnhandledException (innerException ?? javaException);
} else if (RuntimeFeature.IsCoreClrRuntime) {
// TODO: what to do here?
} else {
throw new NotSupportedException ("Internal error: unknown runtime not supported");
}
} catch (Exception e) {
Logger.Log (LogLevel.Error, "monodroid", "Exception thrown while raising AppDomain.UnhandledException event: " + e.ToString ());
}
}

Steps to Reproduce

Did you find any workaround?

No response

Relevant log output

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: CoreCLRIssues that only occur when using CoreCLR.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions