Avoid an exception in Exception.GetCaptureState() if the stack trace is empty, it...
authorZoltan Varga <vargaz@gmail.com>
Tue, 5 Jan 2021 15:46:28 +0000 (10:46 -0500)
committerGitHub <noreply@github.com>
Tue, 5 Jan 2021 15:46:28 +0000 (10:46 -0500)
src/mono/netcore/System.Private.CoreLib/src/System/Exception.Mono.cs

index dbe3dcb..8bd7cd6 100644 (file)
@@ -75,7 +75,8 @@ namespace System
             if (_traceIPs != null)
             {
                 stackFrames = Diagnostics.StackTrace.get_trace(this, 0, true);
-                stackFrames[stackFrames.Length - 1].isLastFrameFromForeignException = true;
+                if (stackFrames.Length > 0)
+                    stackFrames[stackFrames.Length - 1].isLastFrameFromForeignException = true;
 
                 if (foreignExceptionsFrames != null)
                 {