Points to the RTL runtime error handler.
ErrorProc: procedure (ErrorCode: Byte; ErrorAddr: Pointer);
procedure (ErrorCode: Byte; ErrorAddr: Pointer) ErrorProc;
In Delphi, ErrorProc is a procedure variable pointing to the runtime error handler. The standard ErrorProc procedure reports the runtime error and terminates the program.
The ErrorProc variable is retained primarily for compatibility with older code. Newer applications should not specify an alternate runtime error procedure using ErrorProc as SysUtils uses this variable to convert runtime errors into exceptions.
If you use SysUtils in your program, it will force ErrorProc to its own routine and convert the runtime error into an exception. When a runtime library error occurs, the ErrorProc is called. The ErrorCode parameter contains the runtime error number and the ErrorAddr parameter contains the machine code address that caused the runtime error.
Delphi Examples:
{ This example demostrates the use of ErrorProc and how to catch runtime errors. } procedure MyErrorProc(ErrorCode : Byte; ErrorPtr : Pointer); var ErrorName : String; begin { Get the "name" of the enum value using RTTI } ErrorName := GetEnumName(TypeInfo(TRuntimeError), ErrorCode); { Show an error box } MessageDlg(Format('Error with code %d (%s) risen at $%X.', [ErrorCode, ErrorName, Integer(ErrorPtr)]), mtError, [mbOK], 0); end; procedure TForm2.btIOErrorClick(Sender: TObject); begin { Try to write something onto the console - will raise an exception. } WriteLn('This will generate an error because there is no' + ' console attached!'); end; {$OVERFLOWCHECKS ON} {$OPTIMIZATION OFF} {$HINTS OFF} procedure TForm2.btOverflowErrClick(Sender: TObject); var b : Cardinal; begin { Simulate an overflow: Note, enabled the overflow checking and disabled optimizations because Delphi's compiler will not compile this code otherwise. } b := $FFFFFFFF; b := b * b; end; {$HINTS ON} {$OPTIMIZATION ON} {$OVERFLOWCHECKS OFF} procedure TForm2.btRuntimeErrorClick(Sender: TObject); begin { Simulate an access violation } System.Error(reAccessViolation); end; procedure TForm2.FormCreate(Sender: TObject); begin { Register my System error proc } ErrorProc := MyErrorProc; end;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|