Exceptions: Difference between revisions

Added Oz example.
m (Fixed lang tags.)
(Added Oz example.)
Line 730:
| _ -> "unknown exception"</lang>
 
=={{header|PerlOz}}==
===Throw exceptions===
Any value can be thrown as an exception. Typically record values are used.
<lang oz>raise sillyError end
raise slightlyLessSilly(data:42 reason:outOfMemory) end</lang>
 
===Catching exceptions===
Exception are caught with pattern matching. Ellipsis indicating additional optional fields are often useful here.
<lang oz>try
{Foo}
catch sillyError then
{Bar}
[] slightlyLessSilly(data:D ...) then
{Quux D}
[] _ then %% an unknown type of exception was thrown
{Baz}
finally
{Fin}
end</lang>
 
=={{header|Perl}}==
<lang perl># throw an exception
die "Danger, danger, Will Robinson!";
Anonymous user