summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--lib/system/excpt.nim15
-rw-r--r--tests/cpp/tcppraise.nim24
2 files changed, 33 insertions, 6 deletions
diff --git a/lib/system/excpt.nim b/lib/system/excpt.nim
index 2a925fd29..767cf3d0d 100644
--- a/lib/system/excpt.nim
+++ b/lib/system/excpt.nim
@@ -342,12 +342,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:
diff --git a/tests/cpp/tcppraise.nim b/tests/cpp/tcppraise.nim
index 84cacf7f0..8f34cb3e4 100644
--- a/tests/cpp/tcppraise.nim
+++ b/tests/cpp/tcppraise.nim
@@ -5,6 +5,9 @@ bar
 Need odd and >= 3 digits##
 baz
 caught
+--------
+Triggered raises2
+Raising ValueError
 '''
 """
 
@@ -45,3 +48,24 @@ try:
 finally:
   for foobar in strs:
     discard
+
+
+# issue #11118
+echo "--------"
+proc raises() =
+  raise newException(ValueError, "Raising ValueError")
+
+proc raises2() =
+  try:
+    raises()
+  except ValueError as e:
+    echo "Triggered raises2"
+    raise e
+
+try:
+  raises2()
+except:
+  echo getCurrentExceptionMsg()
+  discard
+
+doAssert: getCurrentException() == nil
\ No newline at end of file