Exceptions/Catch an exception thrown in a nested call: Difference between revisions
Content added Content deleted
m (Added the Sidef language) |
|||
Line 2,232: | Line 2,232: | ||
in foo at rosetta/catchAnExceptionThrownInANestedCall.sd7(26) |
in foo at rosetta/catchAnExceptionThrownInANestedCall.sd7(26) |
||
in main at rosetta/catchAnExceptionThrownInANestedCall.sd7(35) |
in main at rosetta/catchAnExceptionThrownInANestedCall.sd7(35) |
||
</pre> |
|||
=={{header|Sidef}}== |
|||
<lang ruby>func baz(i) { die "U#{i}" }; |
|||
func bar(i) { baz(i) }; |
|||
func foo { |
|||
[0, 1].each { |bool| |
|||
try { bar(bool) } |
|||
catch { |_, msg| |
|||
msg ~~ /^U0/ ? say "Function foo() caught exception U0" |
|||
: die msg; # re-raise the exception |
|||
}; |
|||
} |
|||
} |
|||
foo();</lang> |
|||
{{out}} |
|||
<pre> |
|||
Function foo() caught exception U0 |
|||
U1 at test.sf line 1. at test.sf line 9. |
|||
</pre> |
</pre> |
||