Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSError and user-cancel induced "errors"



NSApplication handles this by just looking for NSUserCancelledError at the top level. This is rather simplistic, but the idea is that if the operation was cancelled, this error is just passed up as-is to indicate that.
Ali




Begin forwarded message:

From: "Timothy J. Wood" <email@hidden>
Date: September 29, 2005 15:30:01 PDT
To: Cocoa List <email@hidden>
Subject: Re: NSError and user-cancel induced "errors"


On Sep 29, 2005, at 2:55 PM, Ali Ozer wrote:

Tim,
There is NSUserCancelledError which is for this purpose. It's specially treated by the NSError handling machinery in NSDocument/ NSApplication not to put up a panel.
Ali


Hrm... I totally missed that. It's 10.4 only, so we'll still need to do our own thing for 10.3 for a while longer.

The comments in NSResponder.h don't indicate if this has to be the immediate error or if it checks the underlying errors too. I will be fairly common to have a method that might fail for either a 'real' reason or a user-cancelled reason. In this case, another method calling it shouldn't have to check if the returned domain/ code are the special cancelled combination (and then avoid stacking its error on top of the cancel).

In OmniFoundation I've taken the approach of putting a special key in the user info for user-cancel marking. Then, I have a category method:

/*" Returns YES if the receiver or any of its underlying errors has a user info key of OFUserCanceledActionErrorKey with a boolean value of YES. "*/
- (BOOL)causedByUserCanceling;
{
NSError *error = self;
while (error) {
NSDictionary *userInfo = [error userInfo];
if ([[userInfo valueForKey:OFUserCanceledActionErrorKey] boolValue])
return YES;
error = [userInfo valueForKey:NSUnderlyingErrorKey];
}
return NO;
}


  How does NSApplication/NSDocument handle this?

-tim


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >NSError and user-cancel induced "errors" (From: "Timothy J. Wood" <email@hidden>)
 >Re: NSError and user-cancel induced "errors" (From: Ali Ozer <email@hidden>)
 >Re: NSError and user-cancel induced "errors" (From: "Timothy J. Wood" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.