nested finally bug (#7207)
This commit is contained in:
parent
df4f707743
commit
7cbab49645
2 changed files with 25 additions and 2 deletions
|
|
@ -569,7 +569,7 @@ proc genBreakStmt(p: BProc, t: PNode) =
|
||||||
lineF(p, cpsStmts, "goto $1;$n", [label])
|
lineF(p, cpsStmts, "goto $1;$n", [label])
|
||||||
|
|
||||||
proc genRaiseStmt(p: BProc, t: PNode) =
|
proc genRaiseStmt(p: BProc, t: PNode) =
|
||||||
if p.inExceptBlock > 0:
|
if p.inExceptBlock > 0 and p.inExceptBlock == p.nestedTryStmts.len:
|
||||||
# if the current try stmt have a finally block,
|
# if the current try stmt have a finally block,
|
||||||
# we must execute it before reraising
|
# we must execute it before reraising
|
||||||
var finallyBlock = p.nestedTryStmts[p.nestedTryStmts.len - 1].lastSon
|
var finallyBlock = p.nestedTryStmts[p.nestedTryStmts.len - 1].lastSon
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,13 @@
|
||||||
discard """
|
discard """
|
||||||
file: "tfinally.nim"
|
file: "tfinally.nim"
|
||||||
output: "came\nhere\n3"
|
output: '''came
|
||||||
|
here
|
||||||
|
3
|
||||||
|
msg1
|
||||||
|
msg2
|
||||||
|
finally2
|
||||||
|
finally1
|
||||||
|
'''
|
||||||
"""
|
"""
|
||||||
# Test return in try statement:
|
# Test return in try statement:
|
||||||
|
|
||||||
|
|
@ -17,3 +24,19 @@ proc main: int =
|
||||||
|
|
||||||
echo main() #OUT came here 3
|
echo main() #OUT came here 3
|
||||||
|
|
||||||
|
#bug 7204
|
||||||
|
proc nested_finally =
|
||||||
|
try:
|
||||||
|
raise newException(KeyError, "msg1")
|
||||||
|
except KeyError as ex:
|
||||||
|
echo ex.msg
|
||||||
|
try:
|
||||||
|
raise newException(ValueError, "msg2")
|
||||||
|
except:
|
||||||
|
echo getCurrentExceptionMsg()
|
||||||
|
finally:
|
||||||
|
echo "finally2"
|
||||||
|
finally:
|
||||||
|
echo "finally1"
|
||||||
|
|
||||||
|
nested_finally()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue