Name
Raise Keyword
Syntax
raiseObject referenceraiseObject referenceatPointerraise
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-exceptorTApplication.OnExceptionto 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
Containsmethod to return True if the collection contains an item, and False if the item is not in the collection. The normal ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access