我的 viewDidLoad 中的这个 @try-@catch 块在返回时与 EXC_BAD_ACCESS 一起崩溃;在 catch 中执行并且警报也不显示:
@try
{
errorText = @"thumbnails_array";
unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
// Customize unarchiver here
self.thumbnails_array = [unarchiver decodeObjectForKey:@"thumbnails_array"];
[unarchiver finishDecoding];
[unarchiver release];
errorText = @"ThumbNailViewController";
archivePath = [app.phojoArchiveDir stringByAppendingPathComponent:@"ThumbNailViewController.archive"];
data = [NSData dataWithContentsOfFile:archivePath];
unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
// Customize unarchiver here
[unarchiver decodeObjectForKey:@"self"];
[unarchiver finishDecoding];
[unarchiver release];
errorText = @"assetsGroupURL";
archivePath = [app.phojoArchiveDir stringByAppendingPathComponent:@"assetsGroupURL.archive"];
data = [NSData dataWithContentsOfFile:archivePath];
unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
// Customize unarchiver here
app.assetsGroupURL = [unarchiver decodeObjectForKey:@"assetsGroupURL"];
[unarchiver finishDecoding];
[unarchiver release];
}
@catch (NSException *exception)
{
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Phojo is unable to restore the previous editing session." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
[alert release];
NSLog(@"Exception %@ thrown while unarchving %@: Reason: %@ Items in userInfo = %d Stack Trace: %@", [exception name], errorText, [exception reason], [[exception userInfo] count], [NSThread callStackSymbols]);
[self.thumbnails_array release];
self.thumbnails_array = nil;
[app.assetsGroupURL release];
app.assetsGroupURL = nil;
return;
}
此代码在 viewDidLoad 中运行,以检索在应用程序的先前运行期间已存档的数据。我在这段代码中遇到了一个异常,指出存档无法理解。但是随着它崩溃,根本无法让应用程序运行,因为它在启动时和捕获时都会崩溃。有任何想法吗?