We are using CocosDenshion for our games.
When we turn on exception breakpoints in xcode we keep getting exceptions from
status = ExtAudioFileSetProperty(extRef, kExtAudioFileProperty_ClientDataFormat, sizeof(theOutputFormat), &theOutputFormat);
In CDOpenALSupport.m
(note that this exception does not crash the game as it is caught by CocosDenshion but still we want to see if we can prevent these exceptions).
Set the exception breakpoint to handle only Objective-C exceptions. This prevents these Cocosdenshion exceptions from being caught by the breakpoint.
I wager they're nothing to worry about, it's been like that for as long as I can remember.
Related
Visual Studio has this neat feature of popping up a message box whenever an exception is raised allowing you to break on it and inspect the program state even if the exception is theoretically caught later.
I would like to use something like this for logging purposes. Automatically log every exception that is being raised. This would be especially useful in cases where you raise an exception but it is caught in library code even though it should not have been.
Hence the question: Can it be done, if so, how?
Edit: Not sure if this was obvious enough: I do not want to write code to catch, log and rethrow all exceptions everywhere.
You cannot automatically log exceptions that are thrown. You can log exceptions that are created (regardless of whether they are thrown at a later stage) by means of writing your own exception class.
However, I rarely see someone creating an exception without actually throwing that exception; so this might be good enough for you.
I am trying to use one exception handler to handle all exceptions raised by a C++ class. is there a simple way, instead of adding the code to every member function?
Thanks
There's no simple way that you should be doing.
The point of exceptions is that they handle exceptional conditions -- ie: stuff that is unexpected. And that they cause execution to bubble up to code that knows how to handle them. If you have a defined point in your class that should handle all exceptions, either you know they're going to be thrown and want to swallow them (read: you're abusing exceptions) or you don't know they're going to be thrown and just want to swallow them to hide errors (read: you're creating a debugger's nightmare AND abusing exceptions).
If you can't easily handle an exception, just let it be thrown. Don't swallow it, don't pretend it didn't happen.
I completely agree with cHao.
If you just want to make sure that some trivial exception doesn't crash your program, then for example if you are writing a GUI application, you could wrap your event loop in a try/catch block, and then depending on the exception, decide to log it, tell the user, ask for permission to send an error report, make the program shut down (nice if you restart it automatically...), etc. (If it got all the way out of your event loop without being caught, you probably want to know about it!)
When my Visual Studio 2008 C++ command-line application crashes, it sometimes produces this dialog.
CommandProcessor.exe has encountered a problem and needs to close.
We are sorry for the inconvenience. If you were in the middle of something, the information you were working on might be lost. For more informaiton about this error, click here.
I tried this in Release and in Debug mode.
(By the way, the debugger shows that this is a divide by zero error.)
If it is going to crash, I don't want this dialog, which blocks the application. How do I compile my application so that crashes do not produce the dialog?
With /EHa option you can use catch(...) to catch all exceptions included structured exceptions and write a console message. You can also use VC++ - specific __try for structured exception handling instead, but that's a bit harder to code.
However this will not protect you against situations when terminate() is called by the C++ runtime - like when an exception escapes a destructor during stack unwinding - you will also have to change the terminate() handler by calling set_terminate().
Read series of articles Exception Handling and Crash Reporting. It is possible to catch exception and process it as you wish (you can save crash dump for instance).
I am maintaining a project which uses inter-process COM with C++. At the top level of the callee functions there are try/catch statements directly before the return back through COM. The catch converts any C++ exceptions into custom error codes that are passed back to the caller through the COM layer.
For the purpose of debugging I want to disable this try/catch, and simply let the exception cause a crash in the callee process (as would normally happen with an uncaught C++ exception). Unfortunately for me the COM boundary seems to swallow these uncaught C++ exceptions and I don't get a crash.
Is there a way to change this behaviour in COM? Ie, I want it to allow the uncaught C++ exception to cause a crash in the callee process.
I want this to happen so that I can attach a debugger and see the context in which the exception is thrown. If I simply leave our try/catch in place, and breakpoint on the catch, then the stack has already unwound, and so this is too late for me.
The original "COM masters" who wrote this application are all either unavailable or can't remember enough details.
This just in, a year and a half after the question was asked -
Raymond Chen has written a post about "How to turn off the exception handler that COM 'helpfully' wraps around your server". Seems like the ultimate answer to the question. If not for the OP, for future readers.
I don't think you can disable this behaviour, however there is a way around it if you are using Visual Studio and don't mind getting flooded in exceptions. If you go to Debug>Exceptions in VS and select "When the exception is thrown>Break into the Debugger" for C++ exceptions, it will drop into the debugger at the point the exception is thrown. Unfortunately you then get to work out which exceptions you can ignore and which ones are of interest to you.
The default setting for this is "Continue" with "If the exception is not handled" being set to "break into the debugger". If it doesn't do that already this would suggest that you'll have to find out exactly where the exceptions are being caught.
If I understand correctly, your problem is essentially the inability to get a stack trace from a C++ exception. I've never tried it myself, but it should actually be possible to get the stack trace even from within the catch block.
See: Getting an exception call stack from the catch block
The article describes the process of getting the stack trace using a debugger, but if you don't want one to be attached you can create a dump in the catch clause (one way, another), and then go through the process on your leisure.
Have a look at Vectored Exception Handlers -- depending on your exact use case, VEH could be used to intercept SEH exception handling and force crashes/dumps/whatever.
You can set up a level 2 break in debugger with sxe/sxd -c2 eh that will catch only unhandled C++ exceptions. You can also attach the debugger on the fly to your process at load time using GFlags. Of course you'd have to give up the mickey mouse debugger and use the real deal.
What you need is to enable "break when an exception is thrown" in your debugger. This way you will stop immediately when an exception is thrown and have the entire call stack at your service.
I'm using Visual C++ 2003 to debug a program remotely via TCP/IP.
I had set the Win32 exception c00000005, "Access violation," to break into the debugger when thrown. Then, I set it back to "Use parent setting." The setting for the parent, Win32 Exceptions, is to continue when the exception is thrown.
Now, when I debug the program, it breaks each time that exception is thrown, forcing me to click Continue to let it keep debugging. How do I get it to stop breaking like this?
I'd like to support Will Dean's answer
An access violation sounds like an actual bug in your code. It's not something I'd expect the underlying C/++ Runtime to be throwing and catching internally.
The 'first-chance-exceptions' feature is so you can intercept things which get 'caught' in code, using the debugger, and have a look. If there's nothing 'catching' that exception (which makes sense, why on earth would you catch and ignore access violations?), then it will trigger the debugger regardless of what options you may have set.
Is this an exception that your code would actually handle if you weren't running in the debugger?
Ctrl+Alt+E (or Debug\Exceptions)
From there you can select which exceptions break.