RunError Procedure
The RunError
procedure halts the program with an
error status. RunError
is not a real procedure.
When a runtime error occurs, if ErrorProc
is
nil
, Delphi calls RunError
to
print an error message and stop the program. In a GUI application,
Delphi shows the error message in a dialog box. In a console
application, Delphi prints the error message to the
console.
If you write your own ErrorProc
procedure, you can
call RunError
to halt the program and display a
brief error message, but most likely you will want your
ErrorProc
procedure to do something different,
such as raise an exception or print a different error message.
The ExitProc
procedure and units’
finalization sections get to run before the program terminates.
Like Halt
, RunError
is a quick
way to terminate a program, but not usually the right way for a GUI
application. Instead, you should close the main form to terminate the
application.
// Report a run-time error. The address of the call to RunError
// is the error address. The address passed to ErrorProc is
// the address of the call to ErrorProc, which is close to,
// but not quite the same as, the address of the call to
// RunError. You can adjust the value returned by Caller,
// but that would be highly dependent on Delphi's code generator.
procedure ReportError(ErrorCode: Integer);
function Caller: Pointer;
asm
MOV EAX, [ESP]
end;
type
TErrorProc = procedure(Code: Integer; Addr: Pointer);
begin
if ErrorProc <> nil then
TErrorProc(ErrorProc)(ErrorCode, Caller);
RunError(ErrorCode);
end;