3

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

yibuyiqu
  • 728
  • 1
  • 7
  • 20
  • What type of "additional info" you want to log ? – βhargavḯ Apr 22 '13 at 04:11
  • @Bhargavi: I want to track specific device and user info(e.g. device id, email, etc). – yibuyiqu Apr 22 '13 at 04:23
  • @ShivanRaptor: I am not asking how to use try-catch block. I wonder if I put try-catch in didFinishLaunchingWithOptions and wrap all previous lines in, does it catch all potential crashes even I start threads in somewhere else? – yibuyiqu Apr 22 '13 at 04:29
  • Show us your codes first. – Raptor Apr 22 '13 at 04:31
  • @ShivanRaptor, please see my update above. – yibuyiqu Apr 22 '13 at 04:44
  • Noted the updated codes. My opinion: Use Try-Catch block on codes that will easily raise exception only ( e.g. those connecting to network ) . Initializing a View Controller normally won't have exception, as you have already encountered it when you build & run the app. – Raptor Apr 22 '13 at 05:49

1 Answers1

0

Have you looked into the TestFlight API? It's incredibly easy to implement, free and sounds like it will accomplish what you want. It has built-in remote exception handling and remote logging (you just use TFLog like you would NSLog). You can log UDID's and track users for beta or enterprise distribution, just be aware that Apple won't allow you to collect UDID's in an app store app so you'll have to disable it for that release--you'll still get crash logs and other metrics, they'll just be anonymous.

www.testflightapp.com

Reid
  • 1,109
  • 1
  • 12
  • 27