2009-07-14 17 views
9

我正在使用來自http://code.google.com/p/google-toolbox-for-mac的GTMStackTrace。NSSetUncaughtExceptionHandler未捕獲iPhone上的所有錯誤

我需要一種方式來測試最終用戶在應用崩潰時向我發送錯誤。我知道如何將數據發送到我的網站,但問題是如何捕獲所有未處理的錯誤。

我有這樣的代碼:

void exceptionHandler(NSException *exception) { 
    NSLog(@"%@", [exception reason]); 
    NSLog(@"%@", [exception userInfo]); 
    NSLog(@"%@", GTMStackTraceFromException(exception)); 

    UIAlertView *alert = [[UIAlertView alloc] 
          initWithTitle:NSLocalizedString(@"Error unexpected",@"Info: Can't save record") 
          message:GTMStackTraceFromException(exception) delegate:nil 
          cancelButtonTitle:NSLocalizedString(@"Ok",@"Button: Ok") otherButtonTitles:nil]; 
    [alert show]; 
    [alert release];  
} 

int main(int argc, char *argv[]) { 
    //For crash report.. 
    NSSetUncaughtExceptionHandler(&exceptionHandler); 
    //Normal code... 
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 
    int retVal = UIApplicationMain(argc, argv, nil, nil); 
    [pool release]; 
    return retVal; 
} 

然而,事情不是抓了很多的錯誤,像一個壞的版本,一個BAD ACCES等,和App消失。我有兩個問題不清楚爲什麼happend和最終用戶不知道該說些什麼。

(例如釋放兩次相同的變種沒有趕上)

那麼,如何讓所有討厭的錯誤,從而使最終用戶簡單的給我發一份崩潰報告嗎?

+0

而且,有可能獲得與錯誤行全堆棧跟蹤? – mamcx 2009-07-14 23:00:27

回答

19

EXC_BAD_ACCESS不會產生異常,它會產生一個信號(SIGSEGV)。爲了抓住它,你需要一個信號處理程序。克里斯托弗阿特蘭寫了一個nice explanation如何處理這兩種崩潰。請務必閱讀part 1part 2