public
procedure AppException(Sender: TObject; E: Exception);
...
procedure TForm1.AppException(Sender: TObject; E: Exception);
{错误陷阱}
var
sMsg : string;
begin
sMsg := '你死定了,乱搞破坏!';
ShowMessage(sMsg);
{在这里做你想做的事情}
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnException := AppException; //设置错误陷阱
...
end;