I am a Java programmer working with C++ code, and need some help with exception handling.
I have code in the following structure:
try{
...
}
catch( ... )
{
log("Exception occurred");
}
An exception is occurring, but the try block is really massive and debugging is not an option, so I need to minimally modify the code to give me relevant info on the exception.
So I added the following catch block before the existing catch block (working with my Java knowledge and referring to C++ guides):
catch(exception e)
{
log(e.what());
}
However, I am still getting the old message – “Exception occurred”. The code in try block contains a lot of low level functions like strncpy, memcpy etc.
Why is this catch block not working as expected? What can I do to get information on the exception that is occurring and on which line, similar to the stack trace that Java so easily gives.
You will have to debug and determine if the exception is an C++ exception.
Note that divide by
0etc are runtime exceptions not supported by C++, so it can be anything literally.A catch-all handler will only catch valid C++ exceptions not all exceptions(which can be plenty).