這個@ try- @ catch塊在我的viewDidLoad中崩潰時返回EXC_BAD_ACCESS;在抓執行,並警告不顯示或者:ios @try @catch block 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中運行檢索了該應用的先前運行期間已歸檔數據。我在這段代碼中得到了一個異常,說明一個檔案是不可理解的。但隨着它崩潰,無法讓應用程序運行,因爲它在啓動時崩潰以及捕獲。有任何想法嗎?
請注意,Cocoa中的異常不是您可以從中恢復的錯誤。實際上,Apple表示,ARC的內存管理有意地打破了例外:http://blog.random-ideas.net/?p=98。嘗試避免讓代碼拋出異常比試圖從它們中恢復可能更好。 – 2012-02-10 17:47:28