Exceptions: Difference between revisions

→‎{{header|langur}}: added curly braces to catch for clarity
(Applesoft BASIC)
(→‎{{header|langur}}: added curly braces to catch for clarity)
Line 1,610:
An else section on a catch is optional. As of 0.7, you can also use else if on a catch.
 
=== shortenedexception catchvariable ===
AAn catchexception canvariable may be shortenedspecified, byor usingyou acan singlesimply expressionuse thatthe does not start with aimplicit variable, name.which This uses the implicitis _err exception variable. 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
 
catch if _err["cat"] == "math" {
if _err["cat"] == "math" {
# change result
123
} else {
throw} else {
throw
}
}</syntaxhighlight>
 
<syntaxhighlight lang="langur">val .safediv = f { .x / .y ; catch { 0 } }
.safediv(7, 7) # 1
.safediv(7, 0) # 0</syntaxhighlight>
890

edits