Exceptions: Difference between revisions

Content added Content deleted
(add some details for coldfusion)
(Ada section is extended)
Line 4: Line 4:
=={{header|Ada}}==
=={{header|Ada}}==
===Define an exception===
===Define an exception===
<ada>
Foo_Error : Exception;
Foo_Error : exception;
</ada>
===Raise an exception===
===Raise an exception===
<ada>
procedure Foo is
procedure Foo is
begin
begin
raise Foo_Error;
raise Foo_Error;
end Foo;
end Foo;
</ada>
Re-raising once caught exception:
<ada>
...
exception
when Foo_Error =>
if ... then -- Alas, cannot handle it here,
raise; -- continue propagation of
end if;
</ada>
===Handle an exception===
===Handle an exception===
<ada>
procedure Call_Foo is
procedure Call_Foo is
begin
begin
Foo;
Foo;
exception
exception
when Foo_Error =>
when Foo_Error =>
-- do something
... -- do something
end Call_Foo;
when others =>
... -- this catches all other exceptions
end Call_Foo;
</ada>
===Ada.Exceptions===
The standard package Ada.Exceptions provides a possibility to attach messages to exceptions, to get exception occurrence information and textual description of exceptions. The following example illustrates basic functionality of:
<ada>
with Ada.Exceptions; use Ada.Exceptions;
with Ada.Text_IO; use Ada.Text_IO;

procedure Main is
begin
...
Raise_Exception (Foo_Error'Identity, "This is the exception message");
..
exception
when Error : others =>
Put_Line ("Something is wrong here" & Exception_Information (Error));
end Main;
</ada>
=={{header|AppleScript}}==
=={{header|AppleScript}}==
===try===
===try===