diff options
Diffstat (limited to 'tests/exception/texceptions.nim')
-rw-r--r-- | tests/exception/texceptions.nim | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/exception/texceptions.nim b/tests/exception/texceptions.nim new file mode 100644 index 000000000..69b2d0f6a --- /dev/null +++ b/tests/exception/texceptions.nim @@ -0,0 +1,66 @@ +discard """ + output: ''' +BEFORE +FINALLY + +BEFORE +EXCEPT +FINALLY +RECOVER + +BEFORE +EXCEPT +FINALLY +''' +""" + +echo "" + +proc no_expcetion = + try: + echo "BEFORE" + + except: + echo "EXCEPT" + raise + + finally: + echo "FINALLY" + +try: no_expcetion() +except: echo "RECOVER" + +echo "" + +proc reraise_in_except = + try: + echo "BEFORE" + raise newException(EIO, "") + + except EIO: + echo "EXCEPT" + raise + + finally: + echo "FINALLY" + +try: reraise_in_except() +except: echo "RECOVER" + +echo "" + +proc return_in_except = + try: + echo "BEFORE" + raise newException(EIO, "") + + except: + echo "EXCEPT" + return + + finally: + echo "FINALLY" + +try: return_in_except() +except: echo "RECOVER" + |