C++ – a R6010 error

cexceptionvisual c++windows

I ran into a problem whereby my executable may receive an abort/retry/ignore dialog such as:

Debug Error!
Program: …whatever.exe

R6010
– abort() has been called

I believe it is because I have an unhandled exception and I can replicate the problem with this simple program:

int _tmain(int argc, _TCHAR* argv[])
{
    try
    {
        throw std::exception();
    }
    catch (std::logic_error& e)
    {

    }

    std::cout << "Hello World!";
    return 0;
}

Is my assumption correct (it is caused by an unhandled exception)? I have found plenty of examples online for the error but nothing that actually defines what the error code means.

This error only occurs in my debug build. My release build will just hang before crashing out (which is what I expect for the unhandled exception).

Best Answer

This happens if there's an assertion: assert( condition );.

Assertions are only checked/compiled in the debug build.

Unhandled exceptions make assertions internally, in order to allow the developer to interrupt and debug the program and to find the error.

In release build, the application crashes immediately.

If you remove or catch the exception, the error will not appear anymore.