From 7cfc7cfb26c16c5af4710a653bddbf7e9df1cc25 Mon Sep 17 00:00:00 2001 From: Andrii Riabushenko Date: Tue, 30 Apr 2019 21:46:45 +0100 Subject: [PATCH] fixes #11118 --- lib/system/excpt.nim | 15 +++++++++------ tests/cpp/tcppraise.nim | 24 ++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/lib/system/excpt.nim b/lib/system/excpt.nim index b421d96504..c27169be72 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 84cacf7f0b..8f34cb3e42 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