在 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++ 中?
最佳答案
查看 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
}
关于c++ - VCL 中的 Application.DispatcherUnhandledException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24163683/