Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ retrieve exception information

I have a c++ dll which I need to debug. Due to the circumstances in which I am using the dll, I am unable to debug it via the calling application.

So, I created a try -catch, where the catch writes the exception to a file.

The line which needs to be debugged involves imported classes from a 3rd party dll, so I have no way of knowing what type of exception it is. When I tried catch(exception e), no message was written to the file. So I tried catch(...), which did trigger something:

using std::exception::what, the only thing that got written to the file was "1". using std::exception::exception, the file received the following code : "0579EF90".

Is there any way for me to retrieve meaningful info about the exception that was thrown?

TIA

CG

like image 479
user228058 Avatar asked Jan 12 '10 16:01

user228058


People also ask

Does exception catch all exceptions?

Since Exception is the base class of all exceptions, it will catch any exception.

Can you throw exceptions in C?

The C programming language does not support exception handling nor error handling. It is an additional feature offered by C. In spite of the absence of this feature, there are certain ways to implement error handling in C. Generally, in case of an error, most of the functions either return a null value or -1.

Which component is used to catch exceptions?

Throwing Exceptions from Components Use catch statement to catch specific exceptions (these can be either standard . NET Framework exceptions or your custom exceptions)..

Which of the following is the easiest way to track all unhandled error?

If your application has unhandled exceptions, that may be logged in the Windows Event Viewer under the category of “Application.” This can be helpful if you can't figure out why your application suddenly crashes. Windows Event Viewer may log two different entries for the same exception.


2 Answers

If you don't use catch(KnownExceptionType ex) and use your knwoledge about KnownExceptionType to extract info, no you can't.

When you catch with catch(...) you are pretty much lost, you know that you handled an exception but there is no type information there, there is little you can do.

You are in the worse case, an exception coming out from a library, you have no info on the exception, even if you had headers for the lib, that exception type doesn't need to be defined there.

like image 147
Arkaitz Jimenez Avatar answered Sep 28 '22 05:09

Arkaitz Jimenez


If I understand you correctly, you've already narrowed down the source of the issue to a specific call to a 3rd party library, but you're not allowed to debug the application live (do I want to ask why?), and your question is "how can I debug the exception without any knowledge of what the exception is"

The answer is, you can't. As you observed, you can blindly guess and hope to catch the right thing. You can also catch(...), but that will tell you exactly nothing. If you could debug live, you could set the debugger to break when the exception is thrown and see what is going on there.

I think the right answer though is to contact the 3rd party library you've narrowed down the source of the issue to and ask them. It is very, very bad form to throw an exception and allow it to propogate across module boundries. It makes me suspect that it's a Windows SEH exception for a null pointer deref or something, and you're compiling in such a way that catch(...) catches those.

like image 36
Terry Mahaffey Avatar answered Sep 28 '22 05:09

Terry Mahaffey