What is a R6010 error? - c++

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).

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.

Related

Exception sometimes not caught using C++ / GCC / Linux

Occasionally I encounter a piece of code where an exception is not caught. So far I have no idea what a possible reason can be.
As an example the piece of code below.
The log message "initializing" is printed.
Some log messages from module->Init() are printed
module->init() throws an exception
Log messages in the catch blocks are not printed
Application terminates
log::trace( "Initializing" );
try
{
module->Init();
}
catch( const std::exception& e )
{
log::error( "Error initializing module:{}", e.what());
}
catch( ... )
{
log::error( "Unknown exception initializing module" );
}
dmesg:
[ 9.557049] terminate called after throwing an instance of '
[ 9.562655] std::runtime_error
[ 9.565715] '
[ 9.567350] what():
followed by the error message passed to what() which was the generated exception message in init.
Exception handling works as expected in other parts of the same application.
Exception is thrown from the main thread.
Embedded ARM platform with build system. All libraries are compiled with the same compiler.
Compiler used GCC 8.2.0
Is there anything I am not aware of, which might cause an exception not to be caught ?
Actually overlooked something in the header file. The function was marked "noexcept" which actually caused a terminate when an exception was thrown.

How to get CLion to show exceptions?

I have CLion installed with presumably default configuration. I think something is wrong with it, because I can't see exceptions. For example, this code:
int main(){ throw 5; }
Prints only Process finished with exit code 0
Why doesn't it print the exception?
Why does it print 0 instead of 1?
For comparison:
int main(){try { throw 5; } catch(int x) { std::cout << x << '\n'; }}
This prints 5, so it looks like code is correctly run and the exception is correctly thrown. It's just hidden by CLion somehow.
Edit: This is not a duplicate of "not seeing any console output". I made extremely clear in my question that I was indeed seeing console output for prints. My issue concerns exceptions specifically, not console output generally.
In your first piece of code you have not caught the exception, so it is handled by the default handler. You therefore have no control over the return code from the executable. Operation is as expected.
If you would like CLion to display the exception you can configure it to do so. Note that this will only apply when CLion is debugging your executable, outside of CLion your executable will continue to behave as you have already seen.
Go to run then view breakpoints.
Go to exception breakpoints and when any is thrown.
To display the stack trace when the exception is thrown check stack trace
If you would like your program to stop for your intervention, check enabled and when thrown.
Make sure to use Run/Debug and not Run/Run to launch your program.

log4cpp - Unhandled exception and access violation

Here is some example code I read from some tutorial:
int main(int argc, char* argv[])
{
log4cpp::OstreamAppender* osAppender = new log4cpp::OstreamAppender("osAppender", &cout);
osAppender->setLayout(new log4cpp::BasicLayout());
log4cpp::Category& root = log4cpp::Category::getRoot();
root.addAppender(osAppender);
root.setPriority(log4cpp::Priority::DEBUG);
root.error("Hello log4cpp in a Error Message!");
root.warn("Hello log4cpp in a Warning Message!");
log4cpp::Category::shutdown();
getchar();
return 0;
}
Error report:
Unhandled exception at 0x76fe15de of log4cpp_Test.exe: 0xC0000005: Access violation wile reading 0x00000024
What might have caused the error ?
The code which you have posted is ok. It is compiled and run well.
Are you sure that you have no additional code beside that posted one? The problem might be caused by just few additional lines.
It looks like somewhere NULL pointer is dereferenced, which causes the access violation.
I think you run into this bug ... and it is from 2008.

Where can I see the what() message from an unhandled std::exception in Visual Studio 2012?

Is there a way to see the explanatory string from an unhandled exception? I'm using Visual Studio 2012 Express and can't seem to find a way to see it.
When I run the following code:
#include <stdexcept>
int main(int argc, char* argv[])
{
throw std::runtime_error("warp core breach");
return 0;
}
all I get in the output window is this:
First-chance exception at 0x7652C41F in vstest.exe: Microsoft C++ exception: std::runtime_error at memory location 0x0015F6A4.
Unhandled exception at at 0x7652C41F in vstest.exe: Microsoft C++ exception: std::runtime_error at memory location 0x0015F6A4.
I would have expected the "warp core breach" message to be printed there. I have all options under Debugging->Output Window->General Output Settings set to On.
You'll get a window when the exception is thrown with the option to break/continue/ignore. Copy and paste the hex address this dialog reports, then click the break button. Now in a watch window, enter something like: (std::runtime_error*)(0x002cfbc8) into a cell in the first column.

Throw Causes Program to Crash Instead of going to the Catch Block

I am using NetBeans 7.0.1 on Ubuntu 11.10.
I set set up a
try
{
int error;
// Code
if (error) throw error;
}
catch(int errorNumber)
{
// Error handling
}
block. However, when an exception is thrown, I get the following "Signal Caught" box instead of the program going to my catch block.
Signal received: SIGABRT (?) with sigcode ? (?)
From process: ?
For program celltowebimage, pid 30,222
You may discard the signal or forward it and you may continue or pause the process
To control which signals are caught or ignored use Debug->Dbx Configure
Every other time a program I write throws an exception, it goes to the catch block. Why is NetBeans crashing the program instead? An example of the exception number that is thrown is -23. However they are all small, negative numbers and all result in the same problem.