Exceptions/Catch an exception thrown in a nested call: Difference between revisions
Content added Content deleted
m (→{{header|Wren}}: Changed to Wren S/H) |
m (→{{header|Sidef}}: updated code) |
||
Line 3,095: | Line 3,095: | ||
=={{header|Sidef}}== |
=={{header|Sidef}}== |
||
<syntaxhighlight lang="ruby">func baz(i) { die "U#{i}" } |
<syntaxhighlight lang="ruby">func baz(i) { die "U#{i}" } |
||
func bar(i) { baz(i) } |
func bar(i) { baz(i) } |
||
func foo { |
func foo { |
||
[0, 1].each { |i| |
[0, 1].each { |i| |
||
try { bar(i) } |
try { bar(i) } |
||
catch { | |
catch { |msg| |
||
msg ~~ /^U0/ |
msg ~~ /^U0/ ? say "Function foo() caught exception U0" |
||
: die msg # re-raise the exception |
|||
} |
} |
||
} |
} |
||
} |
} |
||
foo() |
foo()</syntaxhighlight> |
||
{{out}} |
{{out}} |
||
<pre> |
<pre> |