RAD Studio VCL Reference
ContentsIndex
PreviousUpNext
TApplication.ShowException Method

Displays a message box for exceptions that are not caught by application code.

Pascal
procedure ShowException(E: Exception);
C++
__fastcall ShowException(Exception E);

The HandleException method calls ShowException by default if no handler is specified for the OnException event. If an exception handler filters exceptions, ShowException is called for those exceptions that are not filtered out. 

To specify how exceptions are handled for an application, write a handler for the OnException event.

Note: Calling ShowException is rarely necessary in a component-based application, since the default exception handler calls ShowException automatically.
 

C++ Examples: 

 

/*
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.
*/

#include <System.hpp>
#include <SysUtils.hpp>

void __fastcall TForm1::FormCreate(TObject *Sender)
{
  Application->OnException = AppException;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::AppException(TObject *Sender, Exception *E)
{
  Application->ShowException(E);
  Application->Terminate();
}

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  throw(Exception("Hardware error: Divide by 0"));
}

 

Delphi Examples: 

{
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.
}
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;

 

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!