Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exceptions handlers and enclosing blocks. #876

Merged
merged 3 commits into from Sep 21, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
49 changes: 49 additions & 0 deletions doc/Language/exceptions.pod6
Expand Up @@ -62,6 +62,55 @@ To handle all exceptions use a C<default> statement.
}
}


## Exceptions handlers and enclosing blocks.

After a CATCH has handled the exception, the block enclosing the CATCH is left.

In other words even exception is handled successfully, the I<rest of code> in the enclosing block will never be executed
as enclosing block gets left immediately:


die "something went wrong ...";

CATCH {
# will definitely catch all the exception
default { .Str.say; }
}

# but this line will be never reached
# as once default exception handler
# gets executed
# a enclosing block - mainline of the program
# will be left immediately

say "This won't be said.";


Output:

something went wrong ...

Compare with this one:

CATCH {

CATCH {
default { .Str.say; }
}

die "something went wrong ...";

}

say "Hi! I am at the outer block!";

Output:

Hi! I am at the outer block!

See also "Resuming of Exceptions" to know who to return control to the statement following the statement that threw the exception.

=head1 X<C<try>|try blocks> blocks

To contain an exception use a C<try> block. Any exception that is thrown in
Expand Down