从不是例程的块中从 CATCH 移相器返回值的语法是什么?
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)
编辑:所需的输出是:
say baz(); # (baz baz baz)
用例是使用间歇map
性Seq
抛出异常的方法,通过返回默认值来处理传递给 map 的块内的异常。