breaking on failed NSAsserts

June 16, 2008

My code was crashing, with output on the console:

*** Assertion failure in -[NSTextFieldCell _objectValue:forString:], AppKit.subproj/NSCell.m:1131
An uncaught exception was raised
Invalid parameter not satisfying: aString != nil

So I set a breakpoint at - [NSException raise].  I hit the breakpoint, but the next call on the stack was runModalForWindow — there was no indication of what code of mine was doing the mischief.  I tried -[NSCell setStringValue:], but hit lots of cases where nothing was wrong.  Finally, after some googling, I tried breaking on:

-[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:]

Which was perfect.  The call stack showed exactly where I was setting the text field string value to nil, which in turn uncovered a bug in my network error checking.