How to get Visual Studio 2013 to display an unhandled exception message?

I throw this error in my C ++ program and do not process it:

throw std::runtime_error("X failed because " + my_string);

I compile and run it using Visual Studio 2013 and get the following error:

Unhandled exception at 0x7617C42D in bla.exe: Microsoft C ++ exception: std :: runtime_error in memory location 0x009FEA98.

How can I see the message "X failed because ..." without handling the error in the code?

+4
source share
2 answers

, , "", , , .

, , , _CxxThrowException. pExceptionObject - ((std::exception*)pExceptionObject)->what() . , .

catch (std::exception& e) .

+1

, what() . catch , , -. :

class ExceptionOutputDebug : public std::exception
{
    public:
    ExceptionOutputDebug(const std::exception& e)
    {
        OutputDebugString(e.what());
        OutputDebugString("\n");
        if (1) // avoids C4702 (unreachable code)
            throw e;
    }
};

:

throw ExceptionOutputDebug(std::runtime_error("Die"));

:

Die
First-chance exception at 0x76CAC42D in blah.exe: Microsoft C++ exception: std::exception at memory location 0x019EFEBC.

, , . , , OutputDebugString - ( , printf ).

+1

Source: https://habr.com/ru/post/1568051/


All Articles