What is the syntax to return a value from a CATCH phaser from a block which is not a Routine?
sub foo() {
<1 2 3>.map: -> $a {
die 'oops';
CATCH { default { 'foo' } }
}
}
sub bar() {
<1 2 3>.map: -> $a {
die 'oops';
CATCH { default { return 'bar' } }
}
}
say foo(); # (Nil, Nil, Nil)
say bar(); # Attempt to return outside of immediatelly-enclosing Routine (i.e. `return` execution is outside the dynamic scope of the Routine where `return` was used)
edit: Desired output is:
say baz(); # (baz baz baz)
The use case is map
ing a Seq
with a method which intermittently throws an exception, handling the exception within the block passed to map by returning a default value.