大佬教程收集整理的这篇文章主要介绍了iOS版.当其他代码已经使用NSSetUncaughtExceptionHandler时,我怎么能捕获异常?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
调用applicationdidFinishLaunchingWithOptions:
NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);
并使用它来处理异常:
void uncaughtExceptionHandler(NSException *exception) { // handling exception }
但我也使用sdk,它已经使用了NSSetUncaughtExceptionHandler.然后我的方法uncaughtExceptionHandler在异常发生时没有调用.
我知道一个app只能是一个处理程序.但我需要它和sdk,这个代码可以处理全局级别的异常.
在这种情况下,您有什么想法我可以使用NSSetUncaughtExceptionHandler吗?或者其他想法如何在全球范围内处理异常?
十分感谢.
此外,您可以存储SDK的处理程序,并在uncaughtExceptionHandler中调用它以使SDK协同工作.
示例代码:
static NSUncaughtExceptionHandler *exceptionHandler = NULL; typedef void (*sighandler_t)(int); static sighandler_t sigHandler = NULL; static void handleException(NSException *E) { //your code ... //call the SDK handler if (exceptionHandler) { exceptionHandler(E); } } static void handleSignal(int signal) { //your code ... if (sigHandler) { sigHandler(signal); } } void installUncaughtExceptionHandler() { // store the SDK handler exceptionHandler = NSGetUncaughtExceptionHandler(); NSSetUncaughtExceptionHandler(&handleException); sigHandler = signal(SIGABRT,handleSignal); signal(SIGILL,handleSignal); signal(SIGSEGV,handleSignal); signal(SIGFPE,handleSignal); signal(SIGBUS,handleSignal); signal(SIGPIPE,handleSignal); }
以上是大佬教程为你收集整理的iOS版.当其他代码已经使用NSSetUncaughtExceptionHandler时,我怎么能捕获异常?全部内容,希望文章能够帮你解决iOS版.当其他代码已经使用NSSetUncaughtExceptionHandler时,我怎么能捕获异常?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。