Nick
Nick

Reputation: 19684

How can I catch all exceptions in IOS 5?

I am battling an issue in which my application crashes while launching. When trying to run my application in the iPhone simulator it immediately breaks in the main function. I cannot determine why this is. In my applicationDelegate I am attempting to catch the exception by using NSSetUncaughtExceptionHandler.

    void uncaughtExceptionHandler(NSException *exception){
    NSLog(@"%@",[exception reason]);
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{  
    NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);
    return YES;
}

This does not seem to help as my application still breaks in main() and never seems to call application:didFinishLaunchingWithOptions:

I have also tried to set the global breakpoint, objc_exception_throw at the user level. Again the application just seems to break on main()

Can someone provide me with some tips or tricks I can use to try and track down this problem?

Thanks a lot!

Upvotes: 0

Views: 685

Answers (1)

Jarsen
Jarsen

Reputation: 7582

In XCode, go to your Breakpoint Navigator (cmd+6).

In the bottom left click on the plus button, click on add Exception Breakpoint. Select All exceptions and On Throw.

This should create a breakpoint that will help you identify where any exceptions are being generated.

Upvotes: 1

Related Questions