Catching all unhandled C++ exceptions?

前端 未结 8 2134
深忆病人
深忆病人 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:52

    This is what I always do in main()

    int main()
    {
        try
        {
            // Do Work
        }
        catch(std::exception const& e)
        {
             Log(e.what());
             // If you are feeling mad (not in main) you could rethrow! 
        }
        catch(...)
        {
             Log("UNKNOWN EXCEPTION");
             // If you are feeling mad (not in main) you could rethrow! 
        }
    }
    

提交回复
热议问题