catch(...)没有捕获异常,我的程序仍然崩溃 [英] catch(...) is not catching an exception, my program is still crashing

查看:479
本文介绍了catch(...)没有捕获异常,我的程序仍然崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的测试仪出现问题,我的应用程序在初始化时崩溃。我添加了更多的日志记录和异常处理功能,但仍然由于通用此程序已停止工作消息而崩溃,而不是触发了我的错误处理。

I'm having a problem with a tester that my application crashes in initialization. I added more logging and exception handling but it still crashes with the generic "this program has stopped working" message rather than triggering my error handling.

鉴于我的main()看起来像这样,并具有 catch(...)在什么情况下不会触发?

Given my main() looks like this and has catch(...) under what circumstances would this not be triggered?

try{
    simed::CArmApp app(0, cmd);
    for(bool done = false;!done;) 
    {
        done = !app.frame();
    }
} catch(const std::runtime_error &e){
    handleApplicationError(e.what());
    return -1;
} catch(...) {
    handleApplicationError("Unknown Error");
    return -999;
}

我的代码正在调用执行OpenGL渲染的库,这是我相信的东西

My code is calling into a library doing OpenGL rendering which is where I believe things are going wrong.

推荐答案

如果C ++ catch(...)块未捕获错误,可能是因为Windows错误。

If a C++ catch(...) block is not catching errors maybe it is because of a Windows error.

在Windows上,有一个名为结构化异常处理,这是操作系统在发生坏事(例如,引用无效的指针,除以零等)时引发异常的地方。之类的例外,因为它们不是C ++例外;而是Windows以C风格定义的严重错误-这是因为Win32是用C编写的,因此C ++异常是不可行的。

On Windows there is a concept called Structured Exception Handling which is where the OS raises "exceptions" when bad things happen such as dereferencing a pointer that is invalid, dividing by zero etc. I say "exceptions" because these are not C++ exceptions; rather these are critical errors that Windows defines in a C-style fashion - this is because Win32 was written in C so C++ exceptions were not viable.

另请参见:

  • Difference between a C++ exception and Structured Exception
  • try-except Statement
  • Method of getting a stack trace from an EXCEPTION_POINTERS struct

基于评论进行更新

如果您同时想要C ++异常处理和SEH,则可以尝试以下(未经测试的)代码:

If you want both C++ exception handing and SEH perhaps you could try the following (untested) code:

__try
{
    try
    {
        // Your code here...
    }
    catch (std::exception& e)
    {
        // C++ exception handling
    }
}
__except(HandleStructuredException())
{
    // SEH handling 
}

这篇关于catch(...)没有捕获异常,我的程序仍然崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆