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

explicit .resume on Broken promise exception "not resumable", implicit fine #6081

Open
p6rt opened this issue Feb 16, 2017 · 4 comments
Open

Comments

@p6rt
Copy link

p6rt commented Feb 16, 2017

Migrated from rt.perl.org#130793 (status was 'open')

Searchable as RT130793$

@p6rt
Copy link
Author

p6rt commented Feb 16, 2017

From @skids

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

@p6rt
Copy link
Author

p6rt commented Feb 16, 2017

From @timo

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-archive.perl.org/perl6/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

@p6rt
Copy link
Author

p6rt commented Feb 16, 2017

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Feb 18, 2017

From @skids

On Thu, 16 Feb 2017 03​:07​:23 -0800, timo wrote​:

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

OK. But that just means this exception type has suddenly become
unresumable (see the bisect logs), when it used to be resumable. So the
question is, should awaiting a Promise that breaks be something you can
resume from, or was this behavioral change intentional?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant