Catching all unhandled C++ exceptions?

前端 未结 8 2131
深忆病人
深忆病人 2020-12-13 19:22

Is there some way to catch exceptions which are otherwise unhandled (including those thrown outside the catch block)?

I\'m not really concerned about all the normal

8条回答
  •  一向
    一向 (楼主)
    2020-12-13 19:51

    This can be used to catch unexpected exceptions.

    catch (...)
    {
        std::cout << "OMG! an unexpected exception has been caught" << std::endl;
    }
    

    Without a try catch block, I don't think you can catch exceptions, so structure your program so the exception thowing code is under the control of a try/catch.

提交回复
热议问题