#include <stdio.h>
#import <Foundation/Foundation.h>

#define SAFE_DECODE(aDecoder, decode)			\
    NS_DURING						\
    [aDecoder decode];					\
    NS_HANDLER						\
    printf("Exception in %s at line %d: %s\n",		\
	   __FILE__, __LINE__,				\
	   [[localException description] UTF8String]);	\
    NS_ENDHANDLER

int
main()
{
    NSAutoreleasePool *pool = [NSAutoreleasePool new];
    NSMutableData *data;
    NSKeyedUnarchiver *aDecoder;

    printf("Reading archive1 ...\n");
    data = [NSMutableData dataWithContentsOfFile: @"archive1"];
    aDecoder = [[NSKeyedUnarchiver alloc] initForReadingWithData: data];
    SAFE_DECODE(aDecoder, decodeIntForKey: @"A");
    SAFE_DECODE(aDecoder, decodeFloatForKey: @"B");
    [aDecoder finishDecoding];
    [aDecoder release];

    printf("Reading archive2 ...\n");
    data = [NSMutableData dataWithContentsOfFile: @"archive2"];
    aDecoder = [[NSKeyedUnarchiver alloc] initForReadingWithData: data];
    SAFE_DECODE(aDecoder, decodeFloatForKey: @"A");
    SAFE_DECODE(aDecoder, decodeIntForKey: @"B");
    [aDecoder finishDecoding];
    [aDecoder release];

    printf("Done\n");
    [pool release];
    return 0;
}
