Exceptions: Difference between revisions

Content added Content deleted
m ("moved" SHORTENED CATCH to under the Langur language.)
Line 1,555: Line 1,555:
A catch can be shortened by using a single expression that does not start with a variable name. This uses the implicit .err exception variable.
A catch can be shortened by using a single expression that does not start with a variable name. This uses the implicit .err exception variable.


A shortened catch does not allow an else section.
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" {
Line 1,563: Line 1,563:
}</lang>
}</lang>


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


=={{header|Lasso}}==
=={{header|Lasso}}==