2

这个@ 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中运行检索了该应用的先前运行期间已归档数据。我在这段代码中得到了一个异常,说明一个档案是不可理解的。但随着它崩溃,无法让应用程序运行,因为它在启动时崩溃以及捕获。有任何想法吗?

+1

请注意,Cocoa中的异常不是您可以从中恢复的错误。实际上,Apple表示,ARC的内存管理有意地打破了例外:http://blog.random-ideas.net/?p=98。尝试避免让代码抛出异常比试图从它们中恢复可能更好。 – 2012-02-10 17:47:28

回答

2

您的assetsGroupURLthumbnails_array属性(或两者)被声明为retain。这很好,但这意味着当您同时拨打[self.theProperty release]self.theProperty = nil时,您会发布theProperty两次:第二个电话使用的是retain-生成的设置程序,并隐式地将release设置为当前值。删除release调用,你不应该再看到EXC_BAD_ACCESS。

+0

你是对的!感谢您捕捉...但是...仍然与EXC_BAD_ACCESS崩溃...我真的很感激你指出这个双发布,因为它最终会成为一个问题。 – user953175 2012-02-10 17:54:15