Jump to content

Exceptions/Catch an exception thrown in a nested call: Difference between revisions

m
Added the Sidef language
m (Added the Sidef language)
Line 2,232:
in foo at rosetta/catchAnExceptionThrownInANestedCall.sd7(26)
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>
 
2,747

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.