Next: 10.2 The try...except statement
Up: 10. Exceptions
Previous: 10. Exceptions
The raise statement is as follows:
Raise statement
This statement will raise an exception. If it is specified, the exception
instance must be an initialized instance of a class, which is the raise
type. The address exception is optional. If itis not specified, the compiler
will provide the address by itself.
If the exception instance is omitted, then the current exception is
re-raised. This construct can only be used in an exception handling
block (see further).
Remark that control never returns after an exception block. The
control is transferred to the first try...finally or
try...except statement that is encountered when unwinding the stack.
If no such statement is found, the Free Pascal Run-Time Library will generate a
run-time error 217 (see also section exceptclasses).
As an example: The following division checks whether the denominator is
zero, and if so, raises an exception of type EDivException
Type EDivException = Class(Exception);
Function DoDiv (X,Y : Longint) : Integer;
begin
If Y=0 then
Raise EDivException.Create ('Division by Zero would occur');
Result := X Div Y;
end;
The class Exception is defined in the Sysutils unit of the rtl.
(section exceptclasses)
root
1999-06-10