summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2017-07-13 04:43:53 +0200
committerAndreas Rumpf <rumpf_a@web.de>2017-07-13 04:43:53 +0200
commit0c271f54208c7ba0bac6ad2da87f60e7c6d8e37c (patch)
treeae815a17059d4292f95e0c524a920e20619ec27e
parent03e0aa37e3d41c77475a2484e9a3d084e26bd8bf (diff)
downloadNim-0c271f54208c7ba0bac6ad2da87f60e7c6d8e37c.tar.gz
fixes #5871
-rw-r--r--lib/system.nim1
-rw-r--r--lib/system/excpt.nim5
-rw-r--r--tests/exception/tfinally3.nim17
3 files changed, 17 insertions, 6 deletions
diff --git a/lib/system.nim b/lib/system.nim
index 424d9694d..8f653c1e0 100644
--- a/lib/system.nim
+++ b/lib/system.nim
@@ -442,6 +442,7 @@ type
                                         ## providing an exception message
                                         ## is bad style.
     trace: string
+    up: ref Exception # used for stacking exceptions. Not exported!
 
   SystemError* = object of Exception ## \
     ## Abstract class for exceptions that the runtime system raises.
diff --git a/lib/system/excpt.nim b/lib/system/excpt.nim
index b0769b269..e35b0bd5d 100644
--- a/lib/system/excpt.nim
+++ b/lib/system/excpt.nim
@@ -73,12 +73,11 @@ proc popSafePoint {.compilerRtl, inl.} =
   excHandler = excHandler.prev
 
 proc pushCurrentException(e: ref Exception) {.compilerRtl, inl.} =
-  #if e.parent.isNil:
-  #  e.parent = currException
+  e.up = currException
   currException = e
 
 proc popCurrentException {.compilerRtl, inl.} =
-  currException = nil # currException.parent
+  currException = currException.up
 
 # some platforms have native support for stack traces:
 const
diff --git a/tests/exception/tfinally3.nim b/tests/exception/tfinally3.nim
index 8bccd1a7f..037ca9553 100644
--- a/tests/exception/tfinally3.nim
+++ b/tests/exception/tfinally3.nim
@@ -1,6 +1,11 @@
 discard """
   file: "tfinally3.nim"
-  output: "false"
+  output: '''false
+Within finally->try
+Traceback (most recent call last)
+tfinally3.nim(24)        tfinally3
+Error: unhandled exception: First [Exception]'''
+  exitCode: 1
 """
 # Test break in try statement:
 
@@ -14,5 +19,11 @@ proc main: bool =
 
 echo main() #OUT false
 
-
-
+# bug #5871
+try:
+  raise newException(Exception, "First")
+finally:
+  try:
+    raise newException(Exception, "Within finally->try")
+  except:
+    echo getCurrentExceptionMsg()