What I want is to catch all crashes and exceptions by myself and add additional info(e.g. user) to save it. Now, my thought is to wrap try-catch block in didFinishLaunchingWithOptions. In catch block, I log the exception and the additional info, and then re-throw it. Is it the correct way to implement that? Thanks in advance.
Updated for code:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
@try {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.loginViewController = [[LoginViewController alloc] init];
self.window.rootViewController = self.loginViewController;
[self.window makeKeyAndVisible];
}
@catch (NSException *exception) {
// Save the exception description and additional info here
...
// And re-throw it.
[exception raise];
}
return YES;
}
Further update: I have tried above code myself, and it can't catch the exceptions happened in other places. I know Google analytics iOS SDK has "sendUncaughtExceptions" property to do similar thing. I think if I implement the similar functionality by myself can provide more flexibility, since we have our own error server(I will upload the error log to our server). Any suggestion appreciate.
Solution: Finally, I got a solution from this blog: http://www.cocoawithlove.com/2010/05/handling-unhandled-exceptions-and.html