簡體   English   中英

如何查看NSError?

[英]How can I view an NSError?

記錄NSError的最佳方法是什么?

- (void)checkThing:(Thing *)thing withError:(NSError *)error {
    NSLog(@"Error: %@", error);
}

給我一個null信息

查看NSError文檔告訴我,您需要執行以下操作:

NSLog(@"%@",[error localizedDescription]);

這應該給你人類可讀的輸出

 NSLog(@"Error: %@", error); 

給我一個空信息

然后errornil ,而不是NSError實例。

這是我用來在開發過程中記錄錯誤的粗略方法; (不適用於Cocoa-touch)

// Execute the fetch request put the results into array
NSError *error = nil;
NSArray *resultArray = [moc executeFetchRequest:request error:&error];
if (resultArray == nil)
{
    // Diagnostic error handling
    NSAlert *anAlert = [NSAlert alertWithError:error];
    [anAlert runModal];
}

NSAlert負責顯示錯誤。

暫無
暫無

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

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