簡體   English   中英

查找與XCode調試器中的錯誤對應的行

[英]Finding line corresponding to error in XCode debugger

當XCode輸出類似'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]:etc.的錯誤時'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]:etc. ,如何找到該objectAtIndex代碼的代碼行?

創建一個新的異常斷點。 它通常會顯示首次拋出異常的位置。 轉到左側的Breakpoints選項卡:

在此輸入圖像描述

在此輸入圖像描述

看看下面的行,
你應該有一個由你和系統運行的方法的回溯。
在那里,您應該找到它所在的方法的名稱。

我剛剛接受了一個現有項目,並添加了類似的崩潰和目的來說明這一點。

我的方法 -

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];  
    self.contacts = [NSMutableArray arrayWithArray: [ARContact loadContacts]];  
    NSLog(@"%@", self.contacts[100]); // Index 100 is outside of the array scope  
    ....  
}  

崩潰的控制台日志(在Xcode的底部)

*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 100 beyond bounds for empty array'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000101a87495 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x00000001007ec99e objc_exception_throw + 43
    2   CoreFoundation                      0x0000000101a2d745 -[__NSArrayM objectAtIndex:] + 213
    3   PhoneBookApp                        0x0000000100001f95 -[ViewController viewWillAppear:] + 261
    4   UIKit                               0x0000000100b1adb5 -[UIViewController _setViewAppearState:isAnimating:] + 422
    5   UIKit                               0x0000000100b38c4d -[UINavigationController _startTransition:fromViewController:toViewController:] + 707  

在這里你可以看到它們發生的相反順序(意味着0是最新的運行,1就在它之前,等等)。

如果你看看數字3和4,你會看到在崩潰之前,有一個對NSArrayobjectAtIndex:方法的調用(第3行),
這個方法從viewWillAppear:調用viewWillAppear:第4行)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM