进一步: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);
}

 

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