ShowException (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

In addition to displaying the exception message, which happens by default, the following code shuts down the application when an exception is not caught and handled. AppException should be declared a method of TForm1.

Code

procedure TForm1.FormCreate(Sender: TObject);
begin
  Application.OnException := AppException;
end;

procedure TForm1.AppException(Sender: TObject; E: Exception);
begin
  Application.ShowException(E);
  Application.Terminate;
end; 

procedure TForm1.Button1Click(Sender: TObject);
begin
  raise EPasswordInvalid.Create('Incorrect password entered');
end;

Uses