0

在 WPF(.net) 中,我可以使用以下代码来处理意外异常并正确退出我的程序。

private void Application_Startup(object sender, StartupEventArgs e) {    
    this.DispatcherUnhandledException += App_DispatcherUnhandledException
}

private void App_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e) {
    // handle unhandled exception 
}

VCL中是否也有类似的东西?甚至在标准 C++ 中?

4

1 回答 1

1

查看TApplication::OnException事件(也是TApplicationEvents包装器组件),例如:

__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 
}
于 2014-06-11T18:07:54.330 回答