Exceptions: Difference between revisions
Content added Content deleted
Langurmonkey (talk | contribs) |
Langurmonkey (talk | contribs) |
||
Line 1,530: | Line 1,530: | ||
</pre> |
</pre> |
||
=={{header| |
=={{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 |
<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 |
<lang langur>catch if .err["cat"] == "math" { |
||
# change result |
# change result |
||
} else { |
} else { |
||
Line 1,563: | Line 1,563: | ||
}</lang> |
}</lang> |
||
<lang |
<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> |