Name
Raise Keyword
Syntax
raiseObject reference
raiseObject reference
atPointer
raise
Description
The raise
statement raises an exception. The
exception object is passed to an exception handler, and Delphi will
automatically free the object when the exception handler finishes.
Usually, the object reference creates a new instance of an exception
object, and the exception class usually inherits from the
Exception
class in the SysUtils
unit, but you are free to raise any object reference as an
exception.
By default, Delphi stores the code address of the
raise
statement as the exception address. You can
specify a different address with the at
directive.
Inside an exception handler, you can use a plain
raise
statement to reraise the current exception.
In this case, Delphi refrains from freeing the exception object until
the next exception handler in the stack gets its chance to handle the
exception.
Tips and Tricks
Low-level code and utilities should report exceptional conditions by raising exceptions. High-level and user interface code should use
try
-except
orTApplication.OnException
to catch and handle exceptions in a user-friendly manner.Raising and handling an exception takes time and processor resources. Do so only for exceptional conditions. Do not use exceptions as a normal way to return information. For example, a collection class might implement the
Contains
method to return True if the collection contains an item, and False if the item is not in the collection. The normal ...
Get Delphi in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.