Re: Debugging an ignored exception
Re: Debugging an ignored exception
- Subject: Re: Debugging an ignored exception
- From: Matt Neuburg <email@hidden>
- Date: Sun, 26 Nov 2006 11:37:32 -0800
- Thread-topic: Debugging an ignored exception
On Sat, 25 Nov 2006 12:41:37 -0800, Matt Neuburg <email@hidden> said:
>On Sat, 25 Nov 2006 19:09:38 +0200, Guy Meyer <email@hidden> said:
>>
>>My application logs the following to the console:
>>
>>*** NSRunLoop ignoring exception '***
>>+[NSArray arrayWithObject:]: attempt to insert nil' that raised
>>during posting of delayed perform with target 4e6c480 and selector
>>'invokeWithTarget:'
>
>As a test, I deliberately created an app that inserts nil into an Array and
>therefore generates this message in the console:
>
>2006-11-25 12:19:08.776 exceptionHandlingTest[8539] *** NSRunLoop ignoring
>exception '*** -[NSCFArray addObject:]: attempt to insert nil' that raised
>during posting of delayed perform with target 354350 and selector 'throwMe:'
>
>Then I linked in the ExceptionHanding framework and added to the app
>delegate's class the following material:
>
>#import <ExceptionHandling/NSExceptionHandler.h>
>
>- (void)applicationWillFinishLaunching:(NSNotification *)aNotification {
> NSExceptionHandler *handler =
> [NSExceptionHandler defaultExceptionHandler];
> [handler setExceptionHandlingMask:NSLogAndHandleEveryExceptionMask];
> [handler setDelegate: self];
>}
>
>- (BOOL)exceptionHandler:(NSExceptionHandler *)sender
> shouldLogException:(NSException *)exception
> mask:(unsigned int)aMask {
> Debugger();
> return NO;
>}
>
>Now when I run the app in the debugger I break and fall into the debugger,
>and sure enough, in the appropriate stack frame I am paused right at the
>line that inserted nil. You might be able to use some modification of this
>technique. If you do a search in the cocoabuilder archives on
>NSExceptionHandler you'll find a lot of interesting information on this
>topic. m.
I appreciate that the above looks like overkill in comparison to setting a
breakpoint on -[NSException raise], but consider what happens in the built
app, not running in the debugger but just running on some user's machine,
when you get an exception like that. Namely, nothing. The app just keeps
running, but it is florfed and the user has no way of knowing this (most
users don't run with the Console open all the time). The above approach lets
you catch such exceptions and put up a dialog in the exceptionHandler:
routine so the user knows something has gone wrong. Therefore it's something
that I do in all my apps anyway. m.
--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
<http://www.amazon.com/gp/product/0596102119>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden