• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Why Don't Cocoa's (Un)Archiving Methods return Errors?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why Don't Cocoa's (Un)Archiving Methods return Errors?


  • Subject: Re: Why Don't Cocoa's (Un)Archiving Methods return Errors?
  • From: Jerry Krinock <email@hidden>
  • Date: Fri, 29 Jul 2011 11:12:15 -0700

I received a reply off-list suggesting that I file a bug.  And I'll certainly do that, but before I do that I'd like to confirm that I'm not overlooking something obvious.

The fact that these methods throw exceptions if their input data cannot be processed is very uncharacteristic of the Cocoa frameworks.  When invoking -archivedDataWithRootObject: on, say, dictionary, finding an un-encodeable object buried somewhere in the dictionary would seem to be quite common.  Similarly, when invoking -unarchiveObjectWithFile:, no programmer can guarantee what may be found on the filesystem.

Has anyone else ever noticed that these methods are exceptionally lame in their lack of error-handling capability?  Is there something about the (un)archiving process which makes it particularly inefficient to detect and handle errors?

Jerry

On 2011 Jul 28, at 23:24, Jerry Krinock wrote:

> With each major update of Mac OS X, Apple updates more classes to return proper NSErrors, deprecating methods which either don't give errors or give outmoded error representations.
>
> But what about NSKeyedArchiver and NSKeyedUnarchiver, in particular these methods…
>
> +[NSKeyedArchiver archivedDataWithRootObject:]
> +[NSKeyedUnarchiver unarchiveObjectWithFile:]
>
> -unarchiveObjectWithFile: takes a file, for heaven's sake.  If someone has messed with the file, eek, it raises an exception.  I generally enclose these methods in @try{} to avoid that.  Very primitive!
>
> Does anyone know why these methods not marked for deprecation?  Is there a reason why we don't we have 21st-century archive/unarchive methods that return errors instead of raise exceptions?

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Why Don't Cocoa's (Un)Archiving Methods return Errors?
      • From: email@hidden
    • Re: Why Don't Cocoa's (Un)Archiving Methods return Errors?
      • From: Jens Alfke <email@hidden>
References: 
 >Why Don't Cocoa's (Un)Archiving Methods return Errors? (From: Jerry Krinock <email@hidden>)

  • Prev by Date: Re: A trap with full screen in Lion
  • Next by Date: Re: Receiving Unicode Input in NSView
  • Previous by thread: Why Don't Cocoa's (Un)Archiving Methods return Errors?
  • Next by thread: Re: Why Don't Cocoa's (Un)Archiving Methods return Errors?
  • Index(es):
    • Date
    • Thread