Exceptions/Catch an exception thrown in a nested call: Difference between revisions
Exceptions/Catch an exception thrown in a nested call (view source)
Revision as of 01:13, 14 April 2024
, 1 month ago→{{header|langur}}
m (→{{header|Wren}}: Changed to Wren S/H) |
Langurmonkey (talk | contribs) |
||
(4 intermediate revisions by 4 users not shown) | |||
Line 23:
F baz(i)
I i == 0
X.throw U0()
E
X.throw U1()
F bar(i)
Line 1,173:
foo()
{
for(i := 0
{
try
Line 2,070:
There is no explicit try block. A catch implicitly wraps the instructions preceding it within a block into a try block.
<syntaxhighlight lang="langur">val .U0 = h{"msg": "U0"}
val .U1 = h{"msg": "U1"}
val .baz =
val .bar =
val .foo =
for .i in [0, 1] {
.bar(.i)
catch {
if _err
writeln "caught .U0 in .foo()"
} else {
Line 2,092 ⟶ 2,090:
}
.foo()
</syntaxhighlight>
{{out}}
Line 3,095 ⟶ 3,094:
=={{header|Sidef}}==
<syntaxhighlight lang="ruby">func baz(i) { die "U#{i}" }
func bar(i) { baz(i) }
func foo {
[0, 1].each { |i|
try { bar(i) }
catch { |
msg ~~ /^U0/
}
}
}
foo()
{{out}}
<pre>
|