Exceptions: Difference between revisions
Content added Content deleted
(Applesoft BASIC) |
Langurmonkey (talk | contribs) (→{{header|langur}}: added curly braces to catch for clarity) |
||
Line 1,610: | Line 1,610: | ||
An else section on a catch is optional. As of 0.7, you can also use else if on a catch. |
An else section on a catch is optional. As of 0.7, you can also use else if on a catch. |
||
=== |
=== exception variable === |
||
An exception variable may be specified, or you can simply use the implicit variable, which is _err. Prior to 0.7, the implicit exception variable was .err. |
|||
A shortened catch does not allow an else section (action for no exception). |
|||
<syntaxhighlight lang="langur">100 / 0 |
<syntaxhighlight lang="langur">100 / 0 |
||
catch |
catch { |
||
if _err["cat"] == "math" { |
|||
# change result |
# change result |
||
123 |
123 |
||
} else { |
|||
} else { |
|||
throw |
|||
} |
|||
}</syntaxhighlight> |
}</syntaxhighlight> |
||
<syntaxhighlight lang="langur">val .safediv = f { .x / .y ; catch 0 } |
<syntaxhighlight lang="langur">val .safediv = f { .x / .y ; catch { 0 } } |
||
.safediv(7, 7) # 1 |
.safediv(7, 7) # 1 |
||
.safediv(7, 0) # 0</syntaxhighlight> |
.safediv(7, 0) # 0</syntaxhighlight> |