summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2019-08-17 10:37:38 +0200
committerGitHub <noreply@github.com>2019-08-17 10:37:38 +0200
commitdb9e27dffd266c0a69ac3d3544fb9aa563676096 (patch)
tree8af8a0048d624b3fbfe8688226fdfbc57db669eb /lib
parentcf09ef47b85363554a3475413481b4f513ef77ae (diff)
parent721ca3e83087c6c4a7299102d04ba912d4f8dbae (diff)
downloadNim-db9e27dffd266c0a69ac3d3544fb9aa563676096.tar.gz
Fixes #11118 (#11964)
* fixes #11118

* Reset closure iter exception before rethrowing
Diffstat (limited to 'lib')
-rw-r--r--lib/system/excpt.nim18
1 files changed, 10 insertions, 8 deletions
diff --git a/lib/system/excpt.nim b/lib/system/excpt.nim
index 2a925fd29..0898ad0fd 100644
--- a/lib/system/excpt.nim
+++ b/lib/system/excpt.nim
@@ -136,8 +136,7 @@ proc popCurrentExceptionEx(id: uint) {.compilerRtl.} =
     prev.up = cur.up
 
 proc closureIterSetupExc(e: ref Exception) {.compilerproc, inline.} =
-  if not e.isNil:
-    currException = e
+  currException = e
 
 # some platforms have native support for stack traces:
 const
@@ -342,12 +341,15 @@ proc raiseExceptionAux(e: ref Exception) =
   if globalRaiseHook != nil:
     if not globalRaiseHook(e): return
   when defined(cpp) and not defined(noCppExceptions):
-    pushCurrentException(e)
-    raiseCounter.inc
-    if raiseCounter == 0:
-      raiseCounter.inc # skip zero at overflow
-    e.raiseId = raiseCounter
-    {.emit: "`e`->raise();".}
+    if e == currException:
+      {.emit: "throw;".}
+    else:
+      pushCurrentException(e)
+      raiseCounter.inc
+      if raiseCounter == 0:
+        raiseCounter.inc # skip zero at overflow
+      e.raiseId = raiseCounter
+      {.emit: "`e`->raise();".}
   elif defined(nimQuirky):
     pushCurrentException(e)
   else: