Exceptions: Difference between revisions

Content added Content deleted
Line 1,530: Line 1,530:
</pre>
</pre>


=={{header|Langur}}==
=={{header|langur}}==
Exceptions in langur are hashes guaranteed to contain certain fields, even if they're empty.
Exceptions in langur are hashes guaranteed to contain certain fields, even if they're empty.


Line 1,537: Line 1,537:
An else section on a catch is optional (available from version 0.5.0 and higher).
An else section on a catch is optional (available from version 0.5.0 and higher).


<lang Langur># do something
<lang langur># do something
throw "not a math exception"
throw "not a math exception"


Line 1,557: Line 1,557:
A shortened catch does not allow an else section (action for no exception).
A shortened catch does not allow an else section (action for no exception).


<lang Langur>catch if .err["cat"] == "math" {
<lang langur>catch if .err["cat"] == "math" {
# change result
# change result
} else {
} else {
Line 1,563: Line 1,563:
}</lang>
}</lang>


<lang Langur>val .safediv = f { .x / .y ; catch 0 }
<lang langur>val .safediv = f { .x / .y ; catch 0 }
.safediv(7, 7) # 1
.safediv(7, 7) # 1
.safediv(7, 0) # 0</lang>
.safediv(7, 0) # 0</lang>