Jump to content

Exceptions: Difference between revisions

(Add page to "Flow control" category.)
Line 1,597:
A catch causes all the statements preceding it within a block to be the implicit try block.
 
<syntaxhighlight lang="langur">throw "not a math exception"
Exceptions in langur are hashes guaranteed to contain certain fields, even if they're empty.
throw "not a math exception"
 
catch[.e] {
<syntaxhighlight lang="langur">throw "not a math exception"
if .e'cat == "math" {
 
catch[.e] {
if .e'cat == "math" {
# change result...
} else {
Line 1,618 ⟶ 1,617:
An exception variable may be specified, or you can simply use the implicit variable, which is _err.
 
<syntaxhighlight lang="langur">100 / 0
100 / 0
 
catch {
Line 1,631:
</syntaxhighlight>
 
<syntaxhighlight lang="langur">val .safediv = fn(.x, .y) { .x / .y ; catch : 0 }
val .safediv = fn(7x, 7y) #{ x / y ; catch : 0 1}
.safediv(7, 07) # 01
safediv(7, 0) # 0
</syntaxhighlight>
 
1,006

edits

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