diff --git a/compiler/vm.nim b/compiler/vm.nim index 8271857370..312a2085b8 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -273,7 +273,7 @@ proc cleanUpOnException(c: PCtx; tos: PStackFrame): abstractPtrs) else: nil #echo typeToString(exceptType), " ", typeToString(raisedType) - if exceptType.isNil or inheritanceDiff(exceptType, raisedType) <= 0: + if exceptType.isNil or inheritanceDiff(raisedType, exceptType) <= 0: # mark exception as handled but keep it in B for # the getCurrentException() builtin: c.currentExceptionB = c.currentExceptionA diff --git a/tests/vm/trgba.nim b/tests/vm/tmisc_vm.nim similarity index 77% rename from tests/vm/trgba.nim rename to tests/vm/tmisc_vm.nim index 923ea1b2e8..6eb3dd6273 100644 --- a/tests/vm/trgba.nim +++ b/tests/vm/tmisc_vm.nim @@ -2,6 +2,8 @@ discard """ output: '''[127, 127, 0, 255] [127, 127, 0, 255] ''' + + nimout: '''caught Exception''' """ #bug #1009 @@ -34,3 +36,16 @@ proc ABGR*(val: int| int64): TAggRgba8 = const c1 = ABGR(0xFF007F7F) echo ABGR(0xFF007F7F).repr, c1.repr + + +# bug 8740 + +static: + try: + raise newException(ValueError, "foo") + except Exception: + echo "caught Exception" + except Defect: + echo "caught Defect" + except ValueError: + echo "caught ValueError"