Hi Johnathan

On 21/03/11, Rick Mann & Jonathan Mitchell wrote:

My NSOperation subclass wraps the call to the network code in a
@try/catch block. But when this exception is raised, the app
terminates due to an uncaught exception.

Exceptions on the main thread of a Cocoa application do not typically
rise to the level of the uncaught exception handler because the global
application object catches all such exceptions.

This might indicate that your exception is not occurring on your main thread.

Check out the section entitled "Controlling a Program's Response to Exceptions".

That is an interesting reference, but the behavior I see doesn't seem to exactly fit a threading hypothesis.

I've set up an uncaught exception handler delegate (a subclass of NSExceptionHandlerDelegate). When Apple's code throws exceptions from, say,

    +[NSObject(NSObject) doesNotRecognizeSelector:]
    +[NSObject(NSObject) doesNotRecognizeSelector:]
    ___forwarding___
    _CF_forwarding_prep_0

    (probably not a separate thread)

or Core Data's

    _PFFaultHandlerLookupRow
    -[NSFaultHandler fulfillFault:withContext:]
    _PF_FulfillDeferredFault
    -[NSManagedObject valueForKey:]
    -[NSFunctionExpression expressionValueWithObject:context:]
    -[NSComparisonPredicate evaluateWithObject:substitutionVariables:]
    _filterObjectsUsingPredicate
    -[NSArray(NSPredicateSupport) filteredArrayUsingPredicate:]

    (maybe a separate thread?)

my local @catch blocks are not invoked - instead, my NSExceptionHandlerDelegate subclass catches them.

The former is easy enough to simulate for testing but the latter needs a real error (doesn't it?). My latest stab-in-the-dark try is to put one or two of the following at the end of troublesome @try blocks:

    [[NSRunLoop mainRunLoop] runUntilDate:[NSDate distantPast]];

I've used those elsewhere (e.g. waiting for NSArrayController newObject to do its thing - don't ask :) and have noticed that they can throw @catch-able exceptions from the Apple frameworks.

That nastiness failing, it would be handy to have a bullet-proof way to @catch any exception originating from a @try block - non-main thread, alternate universe or otherwise.

Cheers,

Steve Steinitz

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please 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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to