Download objects

Transcript
244 - 09: Handling Exceptions
on E: EDivByZero do
begin
Result := 0;
ShowMessage (E.Message);
end;
end;
end;
In the exception-handling statement, we catch the EDivByZero exception, which is
defined by the run-time library. There are a number of these exception types referring to run-time problems (such as a division by zero or a wrong dynamic cast), to
system problems (such as out-of-memory errors), or to component errors (such as a
wrong index). All of these exceptions classes inherit from the base class Exception ,
which offers some minimal features like the Message property I used in the code
above. These classes form an actual hierarchy with some logical structure.
note
Notice that while types in Object Pascal are generally marked with an initial letter T, exception
classes take an exception to the rule and generally start with the letter E.
The Exceptions Hierarchy
Here is a partial list of the core RTL exception classes defined in the SysUtils unit
(most of the other system libraries add their own exception types):
Exception
EArgumentException
EArgumentOutOfRangeException
EArgumentNilException
EPathTooLongException
ENotSupportedException
EDirectoryNotFoundException
EFileNotFoundException
EPathNotFoundException
EListError
EInvalidOpException
ENoConstructException
EAbort
EHeapException
EOutOfMemory
EInvalidPointer
EInOutError
EExternal
EExternalException
EIntError
EDivByZero
ERangeError
EIntOverflow
EMathError
Marco Cantù, Object Pascal Handbook