Jump to content

Exceptions: Difference between revisions

Ada section is extended
(add some details for coldfusion)
(Ada section is extended)
Line 4:
=={{header|Ada}}==
===Define an exception===
<ada>
Foo_Error : Exceptionexception;
</ada>
===Raise an exception===
<ada>
procedure Foo is
begin
raise Foo_Error;
end Foo;
</ada>
Re-raising once caught exception:
<ada>
...
exception
when Foo_Error =>
if ... then -- Alas, cannot handle it here,
raise; -- continue propagation of
Foo end if;
</ada>
===Handle an exception===
<ada>
procedure Call_Foo is
begin
Foo;
Foo;
exception
exception
when Foo_Error =>
when Foo_Error =>
... -- 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}}==
===try===
Cookies help us deliver our services. By using our services, you agree to our use of cookies.