In WPF(.net) I can use the following code to handle unexpected exceptions and exit my programm properly.
private void Application_Startup(object sender, StartupEventArgs e) {
this.DispatcherUnhandledException += App_DispatcherUnhandledException
}
private void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) {
// handle unhandled exception
}
Is something like this availiable in VCL aswell? Or even in standard C++?
Have a look at the TApplication::OnException
event (also the TApplicationEvents
wrapper component), eg:
__fastcall TMainForm::TMainForm(TComponent *Owner)
: TForm(Owner)
{
Application->OnException = &AppException;
}
__fastcall TMainForm::~TMainForm()
{
Application->OnException = NULL;
}
void __fastcall TMainForm::AppException(TObject *Sender, Exception *E)
{
// handle unhandled exception
}