diff options
Diffstat (limited to 'tests/exception/texcpt1.nim')
-rw-r--r-- | tests/exception/texcpt1.nim | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/exception/texcpt1.nim b/tests/exception/texcpt1.nim new file mode 100644 index 000000000..835f3610a --- /dev/null +++ b/tests/exception/texcpt1.nim @@ -0,0 +1,45 @@ +discard """ + outputsub: "-6" +""" +type + ESomething = object of Exception + ESomeOtherErr = object of Exception + ESomethingGen[T] = object of Exception + ESomethingGenRef[T] = ref object of Exception + +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() + +# Issue #7845, raise generic exception +var x: ref ESomethingGen[int] +new(x) +try: + raise x +except ESomethingGen[int] as e: + discard + +try: + raise new(ESomethingGenRef[int]) +except ESomethingGenRef[int] as e: + discard +except: + discard \ No newline at end of file |