Re: Why Don't Cocoa's (Un)Archiving Methods return Errors?
Re: Why Don't Cocoa's (Un)Archiving Methods return Errors?
- Subject: Re: Why Don't Cocoa's (Un)Archiving Methods return Errors?
- From: Martin Wierschin <email@hidden>
- Date: Tue, 02 Aug 2011 12:45:50 -0700
>> When you unarchive one of those strings, code expecting an instance of UnencodableFoo will instead have an NSString, the use of which will likely throw exceptions, eg: when code calls -[UnencodableFoo fooThing]
>
> No, it's not likely if UnencodableFoo is *my* code, because I program defensively when dealing with input data such as an archive :)
To defend against your solution you'd have to test every decoded object in the graph with something like:
if( ! [decodedObject isKindOfClass:[XXExpectedClass class]] ) ...
Otherwise you don't know if you just decoded one of those strings you silently substituted.
Hitting an exception at the time of archiving is much better- it identifies the problem immediately. If you're trying to archive something that can't be archived, you need to know and change your code (eg: write the missing encoding method, choose a different data representation, etc).
~Martin
_______________________________________________
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