diff options
author | Lluis Sanchez <llsan@microsoft.com> | 2019-05-30 21:09:21 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-30 21:09:21 +0300 |
commit | 63d55448ec9385d4cc0977194f4a245444027177 (patch) | |
tree | a447efb25b825d8d87d3bbdc13b4eae9bb3dbdca /main/src/addins | |
parent | b8f5cbf961afdb6a0ccd1dc70b7ec50469aac461 (diff) | |
parent | 5790889871c9add4be64ef2d26a34a3f6ac5c188 (diff) |
Merge pull request #7733 from mono/exception-handling-better
Handle exceptions coming in from glib and objc in a better way
Diffstat (limited to 'main/src/addins')
-rw-r--r-- | main/src/addins/MacPlatform/MacPlatform.cs | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/main/src/addins/MacPlatform/MacPlatform.cs b/main/src/addins/MacPlatform/MacPlatform.cs index f860333842..0b9a6d51d5 100644 --- a/main/src/addins/MacPlatform/MacPlatform.cs +++ b/main/src/addins/MacPlatform/MacPlatform.cs @@ -249,28 +249,26 @@ namespace MonoDevelop.MacIntegration var nsException = ObjCRuntime.Runtime.GetNSObject<NSException> (exceptionPtr); try { - throw new MarshalledObjCException (nsException, Environment.StackTrace); + throw new MarshalledObjCException (nsException); } catch (MarshalledObjCException e) { + LoggingService.LogInternalError ("Unhandled ObjC Exception", e); // Is there a way to figure out if it's going to crash us? Maybe check MarshalObjectiveCExceptionMode and MarshalManagedExceptionMode? - LoggingService.LogInternalError ("Unhandled ObjC exception", e); } + // Invoke the default xamarin.mac one, so if it bubbles up an exception, the caller receives it. oldHandler?.Invoke (exceptionPtr); } sealed class MarshalledObjCException : ObjCException { - public MarshalledObjCException (NSException exception, string stacktrace) : base (exception) + public MarshalledObjCException (NSException exception) : base (exception) { - StackTrace = stacktrace; - } - - public override string StackTrace { get; } + const BindingFlags flags = BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.SetField; - public override string ToString () - { - // Matches normal exception format: - return GetType () + ": " + Message + Environment.NewLine + StackTrace; + var trace = new [] { new StackTrace (true), }; + //// Otherwise exception stacktrace is not gathered. + typeof (Exception) + .InvokeMember ("captured_traces", flags, null, this, new object [] { trace }); } } |