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

imported>Arakov
(2 intermediate revisions by 2 users not shown)
Line 23:
F baz(i)
I i == 0
X.throw U0()
E
X.throw U1()
 
F bar(i)
Line 2,070:
 
There is no explicit try block. A catch implicitly wraps the instructions preceding it within a block into a try block.
 
Prior to 0.7, you would use .err instead of _err for an implicit exception variable.
 
<syntaxhighlight lang="langur">val .U0 = h{"msg": "U0"}
val .U1 = h{"msg": "U1"}
 
val .baz = ffn(.i) throw if(.i==0: .U0; .U1)
val .bar = ffn(.i) .baz(.i)
 
val .foo = fimpure fn() {
for .i in [0, 1] {
.bar(.i)
catch {
if _err["'msg"] == .U0["'msg"] {
writeln "caught .U0 in .foo()"
} else {
Line 2,092 ⟶ 2,090:
}
 
.foo()</syntaxhighlight>
</syntaxhighlight>
 
{{out}}
885

edits