Name
RunError Procedure
Syntax
procedure RunError(ErrorCode: Integer = 0);
Description
The RunError procedure halts the program with an
error status. RunError is not a real procedure.
Tips and Tricks
When a runtime error occurs, if
ErrorProcisnil, Delphi callsRunErrorto 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
ErrorProcprocedure, you can callRunErrorto halt the program and display a brief error message, but most likely you will want yourErrorProcprocedure to do something different, such as raise an exception or print a different error message.The
ExitProcprocedure and units’ finalization sections get to run before the program terminates.Like
Halt,RunErroris 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.
Example
// 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; ...
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