diff options
Diffstat (limited to 'tests/exception')
-rw-r--r-- | tests/exception/tcontinuexc.nim | 2 | ||||
-rw-r--r-- | tests/exception/tdefer1.nim | 27 | ||||
-rw-r--r-- | tests/exception/texceptionbreak.nim | 20 | ||||
-rw-r--r-- | tests/exception/texceptions.nim | 6 | ||||
-rw-r--r-- | tests/exception/texcsub.nim | 8 | ||||
-rw-r--r-- | tests/exception/tfinally.nim | 4 | ||||
-rw-r--r-- | tests/exception/tfinally2.nim | 6 | ||||
-rw-r--r-- | tests/exception/tfinally3.nim | 2 | ||||
-rw-r--r-- | tests/exception/tfinally4.nim | 8 | ||||
-rw-r--r-- | tests/exception/tnestedreturn.nim | 4 | ||||
-rw-r--r-- | tests/exception/tnestedreturn2.nim | 2 | ||||
-rw-r--r-- | tests/exception/tonraise.nim | 8 | ||||
-rw-r--r-- | tests/exception/treraise.nim | 4 | ||||
-rw-r--r-- | tests/exception/tunhandledexc.nim | 2 | ||||
-rw-r--r-- | tests/exception/twrongexc.nim | 2 |
15 files changed, 65 insertions, 40 deletions
diff --git a/tests/exception/tcontinuexc.nim b/tests/exception/tcontinuexc.nim index f618abc14..fb9b523d7 100644 --- a/tests/exception/tcontinuexc.nim +++ b/tests/exception/tcontinuexc.nim @@ -21,7 +21,7 @@ try: stdout.write("E") stdout.write("C") raise newException(EsomeotherErr, "bla") -finally: +finally: echo "caught" #OUT ECcaught diff --git a/tests/exception/tdefer1.nim b/tests/exception/tdefer1.nim index 61439530a..cb3d09b01 100644 --- a/tests/exception/tdefer1.nim +++ b/tests/exception/tdefer1.nim @@ -1,6 +1,11 @@ discard """ output: '''hi -hi''' +hi +1 +hi +2 +B +A''' """ # bug #1742 @@ -16,3 +21,23 @@ import strutils let x = try: parseInt("133a") except: -1 finally: echo "hi" + + +template atFuncEnd = + defer: + echo "A" + defer: + echo "B" + +template testB(): expr = + let a = 0 + defer: echo "hi" # Delete this line to make it work + a + +proc main = + atFuncEnd() + echo 1 + let i = testB() + echo 2 + +main() diff --git a/tests/exception/texceptionbreak.nim b/tests/exception/texceptionbreak.nim index 76e986787..00dd8ed9f 100644 --- a/tests/exception/texceptionbreak.nim +++ b/tests/exception/texceptionbreak.nim @@ -5,20 +5,20 @@ discard """ # First variety try: - raise newException(EOS, "Problem") -except EOS: + raise newException(OSError, "Problem") +except OSError: for y in [1, 2, 3]: discard try: discard - except EOS: + except OSError: discard echo "1" # Second Variety try: - raise newException(EOS, "Problem") -except EOS: + raise newException(OSError, "Problem") +except OSError: for y in [1, 2, 3]: discard for y in [1, 2, 3]: @@ -28,8 +28,8 @@ echo "2" # Third Variety try: - raise newException(EOS, "Problem") -except EOS: + raise newException(OSError, "Problem") +except OSError: block: break @@ -38,8 +38,8 @@ echo "3" # Fourth Variety block: try: - raise newException(EOS, "Problem") - except EOS: + raise newException(OSError, "Problem") + except OSError: break -echo "4" \ No newline at end of file +echo "4" diff --git a/tests/exception/texceptions.nim b/tests/exception/texceptions.nim index 69b2d0f6a..bdf338599 100644 --- a/tests/exception/texceptions.nim +++ b/tests/exception/texceptions.nim @@ -35,9 +35,9 @@ echo "" proc reraise_in_except = try: echo "BEFORE" - raise newException(EIO, "") + raise newException(IOError, "") - except EIO: + except IOError: echo "EXCEPT" raise @@ -52,7 +52,7 @@ echo "" proc return_in_except = try: echo "BEFORE" - raise newException(EIO, "") + raise newException(IOError, "") except: echo "EXCEPT" diff --git a/tests/exception/texcsub.nim b/tests/exception/texcsub.nim index 3dba357f9..02125d2c0 100644 --- a/tests/exception/texcsub.nim +++ b/tests/exception/texcsub.nim @@ -5,12 +5,12 @@ discard """ # Test inheritance for exception matching: try: - raise newException(EOS, "dummy message") -except E_Base: + raise newException(OSError, "dummy message") +except Exception: echo "caught!" -except: +except: echo "wtf!?" - + #OUT caught! diff --git a/tests/exception/tfinally.nim b/tests/exception/tfinally.nim index 16fb3e7da..aa469d9c0 100644 --- a/tests/exception/tfinally.nim +++ b/tests/exception/tfinally.nim @@ -4,14 +4,14 @@ discard """ """ # Test return in try statement: -proc main: int = +proc main: int = try: try: return 1 finally: echo("came") return 2 - finally: + finally: echo("here") return 3 diff --git a/tests/exception/tfinally2.nim b/tests/exception/tfinally2.nim index e1e8d4c7e..f1acf2774 100644 --- a/tests/exception/tfinally2.nim +++ b/tests/exception/tfinally2.nim @@ -7,7 +7,7 @@ D''' """ # Test break in try statement: -proc main: int = +proc main: int = try: block AB: try: @@ -16,14 +16,14 @@ proc main: int = finally: echo("A") echo("skipped") - finally: + finally: block B: echo("B") echo("skipped") echo("C") finally: echo("D") - + discard main() #OUT ABCD diff --git a/tests/exception/tfinally3.nim b/tests/exception/tfinally3.nim index e65661cd0..8bccd1a7f 100644 --- a/tests/exception/tfinally3.nim +++ b/tests/exception/tfinally3.nim @@ -4,7 +4,7 @@ discard """ """ # Test break in try statement: -proc main: bool = +proc main: bool = while true: try: return true diff --git a/tests/exception/tfinally4.nim b/tests/exception/tfinally4.nim index 05c57c4f5..3aa707ff6 100644 --- a/tests/exception/tfinally4.nim +++ b/tests/exception/tfinally4.nim @@ -8,19 +8,19 @@ discard """ var raiseEx = true var returnA = true var returnB = false - -proc main: int = + +proc main: int = try: #A try: #B if raiseEx: - raise newException(EOS, "") + raise newException(OSError, "") return 3 finally: #B echo "B1" if returnB: return 2 echo "B2" - except EOS: #A + except OSError: #A echo "catch" finally: #A echo "A1" diff --git a/tests/exception/tnestedreturn.nim b/tests/exception/tnestedreturn.nim index 591638f0e..1480764f1 100644 --- a/tests/exception/tnestedreturn.nim +++ b/tests/exception/tnestedreturn.nim @@ -7,7 +7,7 @@ discard """ proc test1() = - finally: echo "A" + defer: echo "A" try: raise newException(OSError, "Problem") @@ -19,7 +19,7 @@ test1() proc test2() = - finally: echo "B" + defer: echo "B" try: return diff --git a/tests/exception/tnestedreturn2.nim b/tests/exception/tnestedreturn2.nim index 4bd2d535d..79523a883 100644 --- a/tests/exception/tnestedreturn2.nim +++ b/tests/exception/tnestedreturn2.nim @@ -14,7 +14,7 @@ proc test4() = discard # Should cause unhandled exception error, -# but could cause segmentation fault if +# but could cause segmentation fault if # exceptions are not handled properly. test4() raise newException(OSError, "Problem") diff --git a/tests/exception/tonraise.nim b/tests/exception/tonraise.nim index 1a555dd94..a155f0b8e 100644 --- a/tests/exception/tonraise.nim +++ b/tests/exception/tonraise.nim @@ -4,8 +4,8 @@ success''' """ type - ESomething = object of E_Base - ESomeOtherErr = object of E_Base + ESomething = object of Exception + ESomeOtherErr = object of Exception proc genErrors(s: string) = if s == "error!": @@ -17,14 +17,14 @@ proc foo() = var i = 0 try: inc i - onRaise(proc (e: ref E_Base): bool = + onRaise(proc (e: ref Exception): bool = echo "i: ", i) genErrors("errssor!") except ESomething: echo("ESomething happened") except: echo("Some other error happened") - + # test that raise handler is gone: try: genErrors("error!") diff --git a/tests/exception/treraise.nim b/tests/exception/treraise.nim index cbd0b5f8a..b2a11d34f 100644 --- a/tests/exception/treraise.nim +++ b/tests/exception/treraise.nim @@ -4,8 +4,8 @@ discard """ exitcode: "1" """ type - ESomething = object of E_Base - ESomeOtherErr = object of E_Base + ESomething = object of Exception + ESomeOtherErr = object of Exception proc genErrors(s: string) = if s == "error!": diff --git a/tests/exception/tunhandledexc.nim b/tests/exception/tunhandledexc.nim index aa9d61236..63a402414 100644 --- a/tests/exception/tunhandledexc.nim +++ b/tests/exception/tunhandledexc.nim @@ -18,6 +18,6 @@ when true: genErrors("errssor!") except ESomething: echo("Error happened") - + diff --git a/tests/exception/twrongexc.nim b/tests/exception/twrongexc.nim index 4e921b8a3..b224d4c83 100644 --- a/tests/exception/twrongexc.nim +++ b/tests/exception/twrongexc.nim @@ -7,7 +7,7 @@ try: raise newException(ValueError, "") except OverflowError: echo("Error caught") - + |