C++ get description of an exception caught in catch(…) block

前端 未结 6 1893
感动是毒
感动是毒 2020-12-03 10:07

can I get description of an exception caught by

catch(...)

block? something like .what() of std::exception.

6条回答
  •  执念已碎
    2020-12-03 10:41

    Quoting bobah

    #include 
    
    #include 
    #include 
    #include 
    
    int main()
    {
        try {
            throw ...; // throw something
        }
        catch(...)
        {
            std::exception_ptr p = std::current_exception();
            std::clog <<(p ? p.__cxa_exception_type()->name() : "null") << std::endl;
        }
        return 1;
    }
    

提交回复
热议问题