summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2012-02-17 20:19:14 +0100
committerAraq <rumpf_a@web.de>2012-02-17 20:19:14 +0100
commita13a14327ad1a98776bbd5646c18a4f6cf257029 (patch)
tree5d782b88f91a30e82daceb8232730342c8f91697
parent547e8aa418ee9a851a876e109b483fc987bd87df (diff)
downloadNim-a13a14327ad1a98776bbd5646c18a4f6cf257029.tar.gz
fixes #99
-rwxr-xr-xcompiler/ccgstmts.nim13
-rw-r--r--tests/run/texcpt1.nim30
2 files changed, 37 insertions, 6 deletions
diff --git a/compiler/ccgstmts.nim b/compiler/ccgstmts.nim
index 8e7b05c0f..605440fc3 100755
--- a/compiler/ccgstmts.nim
+++ b/compiler/ccgstmts.nim
@@ -156,11 +156,11 @@ proc blockLeaveActions(p: BProc, howMany: int) =
   for i in countdown(p.popCurrExc-1, 0):
     appcg(p, cpsStmts, "#popCurrentException();$n", [])
 
-proc genReturnStmt(p: BProc, t: PNode) = 
+proc genReturnStmt(p: BProc, t: PNode) =
   p.beforeRetNeeded = true
-  blockLeaveActions(p, min(1, p.nestedTryStmts.len))
   genLineDir(p, t)
   if (t.sons[0].kind != nkEmpty): genStmts(p, t.sons[0])
+  blockLeaveActions(p, min(1, p.nestedTryStmts.len))
   appff(p.s[cpsStmts], "goto BeforeRet;$n", "br label %BeforeRet$n", [])
   
 proc genWhileStmt(p: BProc, t: PNode) = 
@@ -529,7 +529,7 @@ proc genTryStmt(p: BProc, t: PNode) =
   discard cgsym(p.module, "E_Base")
   appcg(p, cpsLocals, "#TSafePoint $1;$n", [safePoint])
   appcg(p, cpsStmts, "#pushSafePoint(&$1);$n" &
-        "$1.status = setjmp($1.context);$n", [safePoint])
+                     "$1.status = setjmp($1.context);$n", [safePoint])
   if optStackTrace in p.Options: 
     appcg(p, cpsStmts, "#setFrame((TFrame*)&F);$n")
   appf(p.s[cpsStmts], "if ($1.status == 0) {$n", [safePoint])
@@ -544,10 +544,11 @@ proc genTryStmt(p: BProc, t: PNode) =
     if blen == 1: 
       # general except section:
       if i > 1: appf(p.s[cpsStmts], "else {$n")
+      appcg(p, cpsStmts, "$1.status = 0;$n", [safePoint])
       inc p.popCurrExc
       genStmts(p, t.sons[i].sons[0])
       dec p.popCurrExc
-      appcg(p, cpsStmts, "$1.status = 0;#popCurrentException();$n", [safePoint])
+      appcg(p, cpsStmts, "#popCurrentException();$n", [])
       if i > 1: appf(p.s[cpsStmts], "}$n")
     else:
       inc p.popCurrExc
@@ -560,11 +561,11 @@ proc genTryStmt(p: BProc, t: PNode) =
               [genTypeInfo(p.module, t.sons[i].sons[j].typ)])
       if i > 1: app(p.s[cpsStmts], "else ")
       appf(p.s[cpsStmts], "if ($1) {$n", [orExpr])
+      appcg(p, cpsStmts, "$1.status = 0;$n", [safePoint])
       genStmts(p, t.sons[i].sons[blen-1])
       dec p.popCurrExc
       # code to clear the exception:
-      appcg(p, cpsStmts, "$1.status = 0;#popCurrentException();}$n",
-           [safePoint])
+      appcg(p, cpsStmts, "#popCurrentException();}$n", [])
     inc(i)
   appf(p.s[cpsStmts], "}$n") # end of if statement
   if i < length and t.sons[i].kind == nkFinally: 
diff --git a/tests/run/texcpt1.nim b/tests/run/texcpt1.nim
new file mode 100644
index 000000000..ec74c9470
--- /dev/null
+++ b/tests/run/texcpt1.nim
@@ -0,0 +1,30 @@
+discard """
+  outputsub: "-6"
+"""
+type
+  ESomething = object of E_Base
+  ESomeOtherErr = object of E_Base
+
+proc genErrors(s: string) =
+  if s == "error!":
+    raise newException(ESomething, "Test")
+  else:
+    raise newException(EsomeotherErr, "bla")
+
+proc raiseBla(): int =
+  try:
+    genErrors("errssor!")
+  except ESomething:
+    echo("Error happened")
+  except:
+    raise
+
+proc blah(): int =
+  try:
+    result = raiseBla()
+  except ESomeOtherErr:
+    result = -6
+
+echo blah()
+
+