//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "ShowException.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
// BeginExample: ShowException
// Method: Forms.TApplication.ShowException
// Event: Forms.TApplication.OnException
// Method: Forms.TApplication.Terminate
// Class: SysUtils.Exception

// BeginCode
/*
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"));
}
// EndCode
// EndExample: ShowException
//---------------------------------------------------------------------------
