Why is cocos2d throwing away exceptions being thrown from my main code? It's making it *incredibly* hard to diagnose issues, as it may take me a long time for me to determine that an exception is being thrown and silently caught (without any logging!). Judiciously trying to catch my own exceptions defeats the point of my exceptions, which is to immediately terminate the program because of a bad state. This also effectively makes NSAsserts useless, as they throw exceptions when the assertions fail, which again are being silently discarded.
Exceptions are getting thrown away?
(9 posts) (5 voices)-
Posted 11 months ago #
-
am i seriously the only person who's using exception handling?
is there a fix for this? googling around found me a patch from a year ago, but it no longer seems to be relevant to 0.99.5.
Posted 11 months ago # -
The NSAssert and NSException that cocos uses prints a message to the console when you're in the debug build configuration. There could be something wrong with your environment if you're not getting any. I would check if the same thing happens when using a new project.
I'm not sure which patch you're referring to, is it this one?
Posted 11 months ago # -
I add an exception breakpoint so that it breaks whenever an NSAssert occurs (or whenever an exception is thrown).
Check here for some details:
http://jf.omnis.ch/archives/2011/04/efficient-exception-debugging-with-xcode-4.html
For the "action - debugger command" field, i use "bt" to get the backtrace and have more details on what caused the exception.Posted 11 months ago # -
@frilla: thanks for the link. i'm guessing that this isn't a cocos2d issue but rather an objective-c runtime issue, judging from the looks of that link. i'm so used to Java and other fully VM environments where exceptions always do the same thing, but i guess in objective-c, sometimes it'll just be console messages, SIGABRTS, or whatnot.
Posted 10 months ago # -
thelee,
You probably already checked this, but do you have "Stop On Objective-C Exceptions" checked in the XCode Run menu?
Also, I posted a few other tips to make debugging (especially stack dumps) easier to trace, in the following thread (8th post): http://www.cocos2d-iphone.org/forum/topic/15724
Hope this helps.
Posted 10 months ago # -
hey questor, thanks for the link, too.
just want to see if i can double-check some things. some of those entries in your .gdbinit sound like they're redundant if i'm breaking on all objective-c exceptions (NSException raise and objc_error_throw). The other one sounds like the option for tracking zombie releases in the xcode scheme manager. and is szone_error the same thing as doing guard malloc?
Posted 10 months ago # -
Yeah, you're right, some of them are redundant.
The zombie release one is for catching invalid accessing of released objects, etc.
Not sure about the szone one, but all of them are very well documented and discussed in various forums, just google them individually and you should find many tutorials about them and their implications. For example, some of them should not be used when building for a submission release, since they will impact memory usage and performance.
Glad to hear you found them useful.
Posted 10 months ago #
Reply
You must log in to post.