From 2aafd3f2331beb7fc5db230efbdd54867b4dc08c Mon Sep 17 00:00:00 2001 From: Jonathan Pobst Date: Thu, 21 Nov 2024 09:07:47 -1000 Subject: [PATCH] Use `JniEnvironment.Runtime.OnUserUnhandledException`. --- src/Java.Interop/Java.Interop/JniRuntime.cs | 6 ++++++ tools/generator/SourceWriters/MethodCallback.cs | 3 +-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Java.Interop/Java.Interop/JniRuntime.cs b/src/Java.Interop/Java.Interop/JniRuntime.cs index 11c715410..ed01a9f80 100644 --- a/src/Java.Interop/Java.Interop/JniRuntime.cs +++ b/src/Java.Interop/Java.Interop/JniRuntime.cs @@ -437,6 +437,12 @@ public virtual bool ExceptionShouldTransitionToJni (Exception e) partial class JniRuntime { + public virtual void OnUserUnhandledException (ref JniTransition transition, Exception e) + { + transition.SetPendingException (e); + Debugger.BreakForUserUnhandledException (e); + } + public virtual void RaisePendingException (Exception pendingException) { JniEnvironment.Exceptions.Throw (pendingException); diff --git a/tools/generator/SourceWriters/MethodCallback.cs b/tools/generator/SourceWriters/MethodCallback.cs index 8f84bb798..913345580 100644 --- a/tools/generator/SourceWriters/MethodCallback.cs +++ b/tools/generator/SourceWriters/MethodCallback.cs @@ -91,8 +91,7 @@ protected override void WriteBody (CodeWriter writer) writer.WriteLine ("} catch (global::System.Exception __e) {"); writer.Indent (); - writer.WriteLine ("__envp.SetPendingException (__e);"); - writer.WriteLine ("global::System.Diagnostics.Debugger.BreakForUserUnhandledException (__e);"); + writer.WriteLine ("JniEnvironment.Runtime.OnUserUnhandledException (ref __envp, __e);"); if (!method.IsVoid) writer.WriteLine ("return default;");