進一步:BSD信號和異常同時捕獲

 void SignalHandler(int signal)
{
//中斷信號
}
 void uncaughtExceptionHandler(NSException *exception)
{
//未捕獲異常
}
 

安裝(與全局異常斷點衝突,當有這樣的斷點是,下面攔截函數失效)

 void InstallUncaughtExceptionHandler()
{
NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);
signal(SIGABRT, SignalHandler);
signal(SIGILL, SignalHandler);
signal(SIGSEGV, SignalHandler);
signal(SIGFPE, SignalHandler);
signal(SIGBUS, SignalHandler);
signal(SIGPIPE, SignalHandler);
}
 

3.具體實例

1.http://cocoawithlove.com/2010/05/handling-unhandled-exceptions-and.html

重點在於嘗試繼續運行程序

告訴用戶那些因爲這些未攔截的異常和信號導致的崩潰,或者自己記錄,甚至可以避開這樣導致的崩潰.不過,如果多個信號攔截了,這可能失效.

非常推薦看看這篇文章

2.http://parveenkaler.com/2010/08/11/crashkit-helping-your-iphone-apps-suck-less/

重點在於記錄異常(之後返回主線程)

 - (void)pumpRunLoop
{
self.finishPump = NO;
CFRunLoopRef runLoop = CFRunLoopGetCurrent();
CFArrayRef runLoopModesRef = CFRunLoopCopyAllModes(runLoop);
NSArray * runLoopModes = (NSArray*)runLoopModesRef;
while (self.finishPump == NO)
{
for (NSString *mode in runLoopModes)
{
CFStringRef modeRef = (CFStringRef)mode;
CFRunLoopRunInMode(modeRef, 1.0f/120.0f, false); // Pump the loop at 120 FPS
}
}
CFRelease(runLoopModesRef);
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章