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