Exceptions: Difference between revisions
→{{header|langur}}
Alextretyak (talk | contribs) m (→{{header|11l}}: X.throw) |
Langurmonkey (talk | contribs) |
||
(5 intermediate revisions by 3 users not shown) | |||
Line 4:
{{omit from|M4}}
{{omit from|Retro}}
[[Category:Flow control]]
This task is to give an example of an exception handling routine
Line 1,596 ⟶ 1,597:
A catch causes all the statements preceding it within a block to be the implicit try block.
▲<syntaxhighlight lang="langur"># do something
throw "not a math exception"
catch
if
# change result...
} else {
Line 1,610 ⟶ 1,609:
} else {
# no exception
}
...▼
An else section on a catch is optional. You can also use else if.
Line 1,618 ⟶ 1,617:
An exception variable may be specified, or you can simply use the implicit variable, which is _err.
<syntaxhighlight lang="langur">
100 / 0
catch {
if _err
# change result
123
} else {
# rethrow the exception
throw
}
}
<syntaxhighlight lang="langur">
safediv(7, 0) # 0
</syntaxhighlight>
=={{header|Lasso}}==
Line 2,260 ⟶ 2,264:
=={{header|Pascal}}==
See [[Exceptions#Delphi | Delphi]]
=={{header|PascalABC.NET}}==
User defined exceptuin class
<syntaxhighlight lang="delphi">
type MyException = class(Exception) end;
</syntaxhighlight>
Throw an exception
<syntaxhighlight lang="delphi">
raise new MyException;
</syntaxhighlight>
Catch an exception
<syntaxhighlight lang="delphi">
try
except
on e: MyException do
statement
end;
</syntaxhighlight>
=={{header|Perl}}==
|