Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i catch all exception in iPhone app

How can I catch all the exceptions in an iPhone app and report to a central server?

I want to have access to the exception messages that occurred on devices (all devices that install my app).

like image 294
Oksana Avatar asked Nov 03 '11 05:11

Oksana


People also ask

How do you catch all exceptions?

Exception handling is used to handle the exceptions. We can use try catch block to protect the code. Catch block is used to catch all types of exception. The keyword “catch” is used to catch exceptions.

What is IOS exception?

In short, exceptions cause applications to crash if left unhandled. They generally occur when trying to perform an operation on an object incorrectly, such as using an out-of-bounds index to access an array item, or passing nil to a method that doesn't accept it.

What is Sigtrap IOS?

EXC_BREAKPOINT (SIGTRAP) and EXC_BAD_INSTRUCTION (SIGILL)A trace trap gives an attached debugger the chance to interrupt the process at a specific point in its execution. On ARM processors, this appears as EXC_BREAKPOINT (SIGTRAP).

What is Exc_breakpoint Sigtrap?

EXC_BREAKPOINT (SIGTRAP) is a trace trap interrupted the process. It gives an attached debugger, if any, a chance to interrupt the process at a specific point in its execution.


1 Answers

In your application delegate you can call NSSetUncaughtExceptionHandler to install a handler to handle uncaught exceptions.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{    
    NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);
}

void uncaughtExceptionHandler(NSException *exception) {
    NSLog(@"%s %@", __PRETTY_FUNCTION__, exception);
}
like image 149
progrmr Avatar answered Sep 21 '22 18:09

progrmr