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 00:11:25 -0400
On Thu, Jul 2, 2009 at 11:17 PM, Jerry Krinock<email@hidden> wrote:
> If -[NSKeyedUnarchiver unarchiveObjectWithData:] is handed a corrupt
> archive, it raises an exception AND crashes the program. I find this to be
> very annoying since, almost always, archives come from files or network
> sources where corruption is possible. Therefore, I have always protected
> this invocation in a try/catch block.
>
> As I was about to do this for about the fifth time this year, I decided to
> use the Method Replacement feature of Leopard to replace this method, once
> and for all, with one that wouldn't crash. I understand that Method
> Replacement should not be done casually because any plug-in code and even
> Cocoa itself will use the replaced method. However, I can't think of any
> usage where a crash would be required behavior.
>
> It seems to work fine, after 10 minutes of testing. Does anyone see any
> problem with this?
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, and it won't run the potential risk of
screwing up code that you don't control.
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