Jump to content

Exceptions: Difference between revisions

Line 1,598:
Exceptions in langur are hashes guaranteed to contain certain fields, even if they're empty.
 
<syntaxhighlight lang="langur">#throw do"not somethinga math exception"
throw "not a math exception"
 
catch [.e] {
if .e["'cat"] == "math" {
# change result...
} else {
Line 1,610 ⟶ 1,609:
} else {
# no exception
}
...
}</syntaxhighlight>
 
An else section on a catch is optional. You can also use else if.
Line 1,621 ⟶ 1,620:
 
catch {
if _err["'cat"] == "math" {
# change result
123
} else {
# rethrow the exception
throw
}
}
}</syntaxhighlight>
 
<syntaxhighlight lang="langur">val .safediv = ffn(.x, .y) { .x / .y ; catch {: 0 } }
.safediv(7, 7) # 1
.safediv(7, 0) # 0</syntaxhighlight>
</syntaxhighlight>
 
=={{header|Lasso}}==
890

edits

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