Exceptions: Difference between revisions

Content added Content deleted
(→‎{{header|J}}: Added throwing of an error.)
m (Spelling/grammar/aesthetics)
Line 1: Line 1:
{{Task}}
{{Task}}
{{Control Structures}}
{{Control Structures}}

This task is to give an example of an exception handling routine and to "throw" a new exception.
This task is to give an example of an exception handling routine and to "throw" a new exception.
=={{header|Ada}}==
=={{header|Ada}}==
Line 40: Line 39:
=={{header|C++}}==
=={{header|C++}}==


C++ has no finally construct. Instead you can do this in the
C++ has no finally construct. Instead you can do this in the destructor of an object on the stack, which will be called
destructor of an object on the stack, which will be called
if an exception is thrown.
if an exception is thrown.


Line 119: Line 117:
=={{header|Forth}}==
=={{header|Forth}}==
Forth's exception mechanism is, like most things in Forth, very simple but powerful.
Forth's exception mechanism is, like most things in Forth, very simple but powerful.
CATCH captures the data and return stack pointers, then exectutes an execution token.
CATCH captures the data and return stack pointers, then executes an execution token.
THROW conditionally throws a value up to the most recent CATCH, restoring the stack pointers.
THROW conditionally throws a value up to the most recent CATCH, restoring the stack pointers.


Line 201: Line 199:
eventSetup = true;
eventSetup = true;
}
}



=={{header|Perl}}==
=={{header|Perl}}==
Line 297: Line 294:
quux()
quux()


Before Python 2.5 it was not possible to use finally and except together. (It was necessary to nest a separate ''try''...''except'' block inside of your ''try''...''finally'' block).
Before Python 2.5 it was not possible to use finally and except together. (It was necessary to nest a separate ''try''...''except'' block inside of your ''try''...''finally'' block).


=={{header|Raven}}==
=={{header|Raven}}==