开发者

wxWidgets exception handling

开发者 https://www.devze.com 2022-12-30 07:16 出处:网络
When unhandled exception is handled in wxWidgets application in Windows, program shows Abort-Retry-Ignore message produced by Widgets exception handler. I want to get normal unhandled exception behavi

When unhandled exception is handled in wxWidgets application in Windows, program shows Abort-Retry-Ignore message produced by Widgets exception handler. I want to get normal unhandled exception behavior: program should terminate with standard Windows unhandled exception dialog. Can I prevent Widgets to cat开发者_运维知识库ch unhanled exceptions?


Override wxApp::OnUnhandledException() and simply call throw there.


In wxWidgets 3.0.8 (maybe earlier versions too) you can override wxApp::OnExceptionInMainLoop. (That is actually the documentation for AppConsole, I couldn't find documentation for App, but it works the same).

If you rethrow from inside that function you probably will get your desired behaviour.

The base class implementation of this function is the wxWidgets Abort/Retry/Ignore dialog.

Note: this is also the thing to do if you want to handle the exception in your own way and resume execution, e.g.:

// In your App class that derived from wxApp
virtual bool OnExceptionInMainLoop() override
{
    try { throw; }
    catch(std::exception &e)
    {
        MessageBoxA(NULL, e.what(), "C++ Exception Caught", MB_OK);
    }
    return true;   // continue on. Return false to abort program
}
0

精彩评论

暂无评论...
验证码 换一张
取 消