Error is used to generate a run-time exception.
procedure Error(errorCode: TRuntimeError);
Error(TRuntimeError errorCode);
Error should be invoked when you want to generate an exception. errorCode defines the type of error to be reported.
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!
|