ShowException (C++)

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

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

__fastcall TForm1::TForm1(TComponent* Owner)
  : TForm(Owner)
{
  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"));
}

Uses