Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
We now fully pass 44-try-catch.t.
- Loading branch information
Showing
1 changed file
with
69 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| #! nqp | ||
|
|
||
| # Tests for try and catch | ||
|
|
||
| plan(8); | ||
|
|
||
| sub oops($msg = "oops!") { # throw an exception | ||
| nqp::die($msg); | ||
| } | ||
|
|
||
| my $ok := 1; | ||
| try { | ||
| oops(); | ||
| $ok := 0; | ||
| } | ||
| ok($ok, "exceptions exit a try block"); | ||
|
|
||
| sub foo() { | ||
| try { | ||
| return 1; | ||
| } | ||
| return 0; | ||
| } | ||
|
|
||
| ok(foo(), "control exceptions are not caught by a try block"); | ||
|
|
||
| ok((try 1532) == 1532,"statement prefix form works when not throwing an exception"); | ||
| ok(nqp::istype((try oops()), NQPMu), "statement prefix form of try works"); | ||
|
|
||
| { | ||
| CATCH { ok(1, "CATCH blocks are invoked when an exception occurs"); } | ||
| oops(); | ||
| } | ||
|
|
||
|
|
||
| $ok := 1; | ||
| sub bar() { | ||
| CATCH { $ok := 0; } | ||
| return; | ||
| } | ||
| bar(); | ||
| ok($ok, "CATCH blocks ignore control exceptions"); | ||
|
|
||
| $ok := 1; | ||
| { | ||
| { | ||
| { | ||
| { | ||
| oops(); | ||
| CATCH { $ok := $ok * 2; nqp::rethrow($!); } | ||
| } | ||
| CATCH { $ok := $ok * 2; nqp::rethrow($!); } | ||
| } | ||
| CATCH { $ok := $ok * 2; nqp::rethrow($!); } | ||
| } | ||
| CATCH { ok($ok == 8, "rethrow and multiple exception handlers work") } | ||
| } | ||
|
|
||
| $ok := 1; | ||
|
|
||
| { | ||
| for 1, 2, 3, 4 { | ||
| $ok := $ok * 2; | ||
| oops(); | ||
| } | ||
| CATCH { nqp::resume($!); } | ||
| } | ||
|
|
||
| ok($ok == 16, "resuming from resumable exceptions works"); |