IOS How can I catch an exception when another code is already using NSSetUncaughtExceptionHandler?

I want to use a global exception handler.

Call applicationdidFinishLaunchingWithOptions:

NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);

And use this to exclude processing:

    void uncaughtExceptionHandler(NSException *exception) {
        // handling exception
}

But also I use sdk, which already uses NSSetUncaughtExceptionHandler. Then my uncaughtExceptionHandler method did not call when an exception occurs.

I know that this can be only one handler for one application. But I need it and sdk, and this code can handle exceptions globally.

Do you have any idea how I can use NSSetUncaughtExceptionHandler in this case? Or other ideas, how can I deal with exceptions globally? Many thanks.

+4
1

installUncaughtExceptionHandler() , SDK NSSetUncaughtExceptionHandler . uncaughtExceptionHandler.

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);
}
0

All Articles