home *** CD-ROM | disk | FTP | other *** search
- unit TestExceptNotifyUnit1;
-
- interface
-
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- StdCtrls;
-
- type
- TForm1 = class(TForm)
- AVBtn: TButton;
- RaiseBtn: TButton;
- NonExceptionBtn: TButton;
- QuitBtn: TButton;
- procedure FormCreate(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- procedure AVBtnClick(Sender: TObject);
- procedure RaiseBtnClick(Sender: TObject);
- procedure NonExceptionBtnClick(Sender: TObject);
- procedure QuitBtnClick(Sender: TObject);
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- uses
- HVExceptNotify;
-
- {$R *.DFM}
-
- procedure NotifyException(ExceptObj: TObject; ExceptAddr: pointer; OSException: boolean);
- const
- Recursive: boolean = false;
- begin
- // We have to be careful what we are doing in here -
- // if an exception is raised, we could get endless recursive behaviour
- if not Recursive then
- begin
- Recursive := true;
- if ExceptObj is Exception then
- ShowMessage(Format('Notified of exception %s at %p'#13#10'"%s"',
- [ExceptObj.ClassName, ExceptAddr, Exception(ExceptObj).Message]))
- else
- ShowMessage(Format('Notified of exception %s at %p',
- [ExceptObj.ClassName, ExceptAddr]));
- Recursive := false;
- end;
- end;
-
- procedure TForm1.FormCreate(Sender: TObject);
- begin
- HVExceptNotify.ExceptNotify := NotifyException;
- end;
-
- procedure TForm1.FormDestroy(Sender: TObject);
- begin
- HVExceptNotify.ExceptNotify := nil;
- end;
-
- procedure TForm1.AVBtnClick(Sender: TObject);
- begin
- SysUtils.StrLen(nil);
- end;
-
- procedure TForm1.RaiseBtnClick(Sender: TObject);
- begin
- SysUtils.StrToInt('');
- end;
-
- procedure TForm1.NonExceptionBtnClick(Sender: TObject);
- begin
- // Any object type can be raised as en exception
- raise TPersistent.Create;
- end;
-
- procedure TForm1.QuitBtnClick(Sender: TObject);
- begin
- Close;
- end;
-
- end.
-