Tip: Debugging exceptions

Don’t you just hate it when you finally get your program linking, you run it, and instead of seeing your glorious code executing away you get something like this?

2008-11-13 21:12:25.866 Play MPE[1369:20b] * -[PMPELoginViewController loginSucceeded:]: unrecognized selector sent to instance 0x40d560

2008-11-13 21:12:25.867 Play MPE[1369:20b] * Terminating app due to uncaught exception

Most annoying, that. So what can you do to catch that kind of nonsense in the act? Or other runtime failures?

Well, the Breakpoints window in Xcode (Run > Show > Breakpoints) is your friend. Simply add these project or global breakpoints:

objc_exception_throw

+[NSException raise:format:]

_NSAutoreleaseNoPool

_objc_fatal

malloc_error_break

and then hey presto, the debugger comes up stopped on the source line, in this case

[self loginSucceeded:loginResultData];

Much easier to debug, that!

[EDIT: And here’s some others you might try as well:

NSInternalInconsistencyException

NSInvalidArgumentException

]

h/t: iphonesdk!

Alex | November 13, 2008

Leave a Reply