To indicate a disruptive error condition, you can raise an exception by constructing an instance of an exception object that describes the error condition and calling the reserved word raise.
To raise an exception, call the reserved word raise, followed by an instance of an exception object. This establishes the exception as coming from a particular address. When an exception handler actually handles the exception, it finishes by destroying the exception instance, so you never need to do that yourself.
For example, given the following declaration,
type EPasswordInvalid = class(Exception);
you can raise a "password invalid" exception at any time by calling raise with an instance of EPasswordInvalid, like this:
if Password <> CorrectPassword then raise EPasswordInvalid.Create('Incorrect password entered');
Raising an exception sets the ErrorAddr variable in the System unit to the address where the application raised the exception. You can refer to ErrorAddr in your exception handlers, for example, to notify the user where the error occurred. You can also specify a value in the raise clause that appears in ErrorAddr when an exception occurs.
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
|
What do you think about this topic? Send feedback!
|