You might be confusing resuming an exception with leaving the CATCH
block with the exception marked as "handled".

When you leave the block after having matched the exception successfully
with a default or when block (or whatever else), the exception is marked
as handled, which means it won't get re-thrown at the end of the CATCH
block.

When you call .resume on an exception, it will continue running the code
in the place where the exception was thrown.

Here's two code examples, one with resume, one without (exceptions
thrown with "die" are resumable.)

    perl6 -e 'sub throws() { die "oh no"; say "inside &throws, after
dying"; }; sub catches { say "before"; throws; say "after"; CATCH {
default { say "caught"; .resume; say "resumed" } }; say "after CATCH" };
catches'
    before
    caught
    inside &throws, after dying
    after
    after CATCH

    perl6 -e 'sub throws() { die "oh no"; say "inside &throws, after
dying"; }; sub catches { say "before"; throws; say "after"; CATCH {
default { say "caught"; say "not resumed" } }; say "after CATCH" }; catches'
    before
    caught
    not resumed

Note also that the CATCH block is something "attached to" the block that
contains it, and as such leaving the CATCH block with success will also
leave the containing block (that's why it says "not resumed", but not
"after CATCH" in the second example)

I'm thinking this is NOTABUG and can be closed, though perhaps the docs
aren't sufficient about exception handling?

On 16/02/17 05:02, Brian S. Julin (via RT) wrote:
> # New Ticket Created by  "Brian S. Julin" 
> # Please include the string:  [perl #130793]
> # in the subject line of all future correspondence about this issue. 
> # <URL: https://rt.perl.org/Ticket/Display.html?id=130793 >
>
>
>
> In abf6caf0 the ability to explicitly .resume an exception caused by awaiting 
> a broken
> promise... broke.  However, implicitly resuming after handling the exception 
> still works fine.
>
> $ perl6 -e 'my $p = Promise.new; my $b = 0; my $w = start { await($p); CATCH 
> { default { $b = 1; .resume } } }; $p.break; await($w); $b.say' Tried to get 
> the result of a broken Promise
>   in block <unit> at -e line 1
>
> Original exception:
>     This exception is not resumable
>       in block  at -e line 1
>       in block  at -e line 1
>
> bri@atlas:~/git/perl6-xcb$ perl6 -e 'my $p = Promise.new; my $b = 0; my $w = 
> start { await($p); CATCH { default { $b = 1; } } }; $p.break; await($w); 
> $b.say'
> 1
>
> various bot output links at:
>
> https://irclog.perlgeek.de/perl6/2017-02-16#i_14111000

Reply via email to