//注意本程序编译后应脱离ide运行才不会显示Exception
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
AppEvnts, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure ApplicationEvents1Exception(Sender: TObject; E: Exception);
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.ApplicationEvents1Exception(Sender: TObject;
E: Exception);
begin
//showmessage('error');//在这里什么都不做,就可以不显示错误信息了
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
raise Exception.Create('raise error');//自己产生一个例外
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
application.OnException:=ApplicationEvents1Exception;//截获exception
的缺省处理
end;
end.