Re: Replace -[NSKeyedUnarchiver unarchiveObjectWithData:] so it doesn't crash on corrupt archive
Re: Replace -[NSKeyedUnarchiver unarchiveObjectWithData:] so it doesn't crash on corrupt archive
- Subject: Re: Replace -[NSKeyedUnarchiver unarchiveObjectWithData:] so it doesn't crash on corrupt archive
- From: Michael Ash <email@hidden>
- Date: Fri, 3 Jul 2009 08:50:58 -0400
On Fri, Jul 3, 2009 at 1:42 AM, Jerry Krinock<email@hidden> wrote:
>
> On 2009 Jul 02, at 21:11, Michael Ash wrote:
>
>> Is there a reason you can't just implement a new method in a category
>> and not replace the existing one? It will be just as safe in your
>> code, just as easy to use,
>
> I'd considered doing that and yes it could be done. But then it would have
> a different method name that I'd have to remember to use instead of
> -unarchiveObjectWithData:.
>
> Replacing a Cocoa method seems like it should only be done if the original
> method shipped by Apple is buggy. I believe that's the case here. The only
> behavior I'm losing is a potential crash.
Well, that's wrong. The behavior you're losing is that of throwing an
exception on error. It is entirely possible that Apple's code relies
on this method throwing an exception on error. As your own code
demonstrates, you can catch the exception in question without
crashing.
You're not fixing a bug, unless you consider throwing an exception to
always be a bug AND you consider any code which relies on catching an
exception to likewise be a bug. You're changing existing non-buggy
behavior. That's a bad thing to do unless you have a VERY good reason,
and IMHO "a different method name that I'd have to remember to use" is
a pretty crappy reason for this.
Mike
_______________________________________________
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