@@ -698,19 +698,21 @@ proc raiseExit(p: BProc) =
698698 lineCg (p, cpsStmts, " if (NIM_UNLIKELY(*nimErr_)) goto LA$1_;$n" ,
699699 [p.nestedTryStmts[^ 1 ].label])
700700
701+ proc finallyActions (p: BProc ) =
702+ if p.config.exc != excGoto and p.nestedTryStmts.len > 0 and p.nestedTryStmts[^ 1 ].inExcept:
703+ # if the current try stmt have a finally block,
704+ # we must execute it before reraising
705+ let finallyBlock = p.nestedTryStmts[^ 1 ].fin
706+ if finallyBlock != nil :
707+ genSimpleBlock (p, finallyBlock[0 ])
708+
701709proc genRaiseStmt (p: BProc , t: PNode ) =
702- if p.config.exc != excGoto:
703- if p.config.exc == excCpp:
704- discard cgsym (p.module, " popCurrentExceptionEx" )
705- if p.nestedTryStmts.len > 0 and p.nestedTryStmts[^ 1 ].inExcept:
706- # if the current try stmt have a finally block,
707- # we must execute it before reraising
708- let finallyBlock = p.nestedTryStmts[^ 1 ].fin
709- if finallyBlock != nil :
710- genSimpleBlock (p, finallyBlock[0 ])
710+ if p.config.exc == excCpp:
711+ discard cgsym (p.module, " popCurrentExceptionEx" )
711712 if t[0 ].kind != nkEmpty:
712713 var a: TLoc
713714 initLocExprSingleUse (p, t[0 ], a)
715+ finallyActions (p)
714716 var e = rdLoc (a)
715717 var typ = skipTypes (t[0 ].typ, abstractPtrs)
716718 genLineDir (p, t)
@@ -724,6 +726,7 @@ proc genRaiseStmt(p: BProc, t: PNode) =
724726 if optOwnedRefs in p.config.globalOptions:
725727 lineCg (p, cpsStmts, " $1 = NIM_NIL;$n" , [e])
726728 else :
729+ finallyActions (p)
727730 genLineDir (p, t)
728731 # reraise the last exception:
729732 if p.config.exc == excCpp:
0 commit comments