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; |
|||
</ada> |
|||
===Raise an exception=== |
===Raise an exception=== |
||
<ada> |
|||
procedure Foo is |
|||
begin |
|||
raise Foo_Error; |
|||
end Foo; |
|||
</ada> |
|||
Re-raising once caught exception: |
|||
<ada> |
|||
... |
|||
⚫ | |||
⚫ | |||
if ... then -- Alas, cannot handle it here, |
|||
raise; -- continue propagation of |
|||
⚫ | |||
</ada> |
|||
===Handle an exception=== |
===Handle an exception=== |
||
<ada> |
|||
procedure Call_Foo is |
|||
begin |
|||
⚫ | |||
Foo; |
|||
⚫ | |||
exception |
|||
⚫ | |||
when Foo_Error => |
|||
-- do something |
... -- do something |
||
⚫ | |||
when others => |
|||
... -- this catches all other exceptions |
|||
⚫ | |||
</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=== |