diff --git a/compiler/ccgstmts.nim b/compiler/ccgstmts.nim index 9c7bced331..a69495a4b7 100644 --- a/compiler/ccgstmts.nim +++ b/compiler/ccgstmts.nim @@ -788,30 +788,13 @@ proc genTryCpp(p: BProc, t: PNode, d: var TLoc) = # myDiv(4, 9); # } catch (NimExceptionType1&) { # body - # goto LA_END; # } catch (NimExceptionType2&) { # finallyPart() # raise; - # goto LA_END; - # } catch (NimExceptionType3&) {goto LA1;} - # } catch (NimExceptionType4&) {goto LA1;} - # } catch (NimExceptionType5&) {goto LA2;} - # } catch (NimExceptionType6&) {goto LA2;} + # } # catch(...) { - # // general handler - # goto LA_END; + # general_handler_body # } - # {LA1: - # labeled_branch_body_LA1 - # goto LA_END; - # } - # {LA2: - # labeled_branch_body_LA2 - # finallyPart() - # raise; - # goto LA_END; - # } - # LA_END: # finallyPart(); template genExceptBranchBody(body: PNode) {.dirty.} = @@ -819,22 +802,19 @@ proc genTryCpp(p: BProc, t: PNode, d: var TLoc) = linefmt(p, cpsStmts, "#setFrame((TFrame*)&FR_);$n") expr(p, body, d) linefmt(p, cpsStmts, "#popCurrentException();$n") - linefmt(p, cpsStmts, "goto $1;$n", end_label) - if not isEmptyType(t.typ) and d.k == locNone: getTemp(p, t.typ, d) genLineDir(p, t) + let end_label = getLabel(p) discard cgsym(p.module, "Exception") add(p.nestedTryStmts, t) startBlock(p, "try {$n") expr(p, t[0], d) - endBlock(p, ropecg(p.module, "}")) + endBlock(p) - let end_label = getLabel(p) var catchAllPresent = false - var labeled_branches: seq[tuple[label: Rope, body: PNode]] = @[] # generated after labels discovered inc p.inExceptBlock for i in 1..= 3 digits## -baz''' +baz +caught +''' """ # bug #1888 @@ -15,3 +17,21 @@ try: except ValueError: echo getCurrentExceptionMsg(), "##" echo "baz" + + +# bug 7232 +try: + discard +except KeyError, ValueError: + echo "except handler" # should not be invoked + + +#bug 7239 +try: + try: + raise newException(ValueError, "asdf") + except KeyError, ValueError: + raise +except: + echo "caught" +