Fix Crittercism’s lack of logging

Crittercism does not log exceptions to the console, which sucks while you’re developing. To fix this, you can proxy their exception handler with your own, something like this:

  1. @implementation AppDelegate
  2.  
  3. void myExceptionHandler (NSException * exception){
  4.     NSLog(@"Caught top-level exception: %@: %@\nStack:\n%@",
  5.         exception.name, exception.reason, [NSThread callStackSymbols]);
  6.     crittercismHandler(exception);
  7. }
  8.  
  9. static NSUncaughtExceptionHandler* crittercismHandler;
  10.  
  11. (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  12.     [Crittercism enableWithAppID:@"your app id"];
  13.     crittercismHandler = NSGetUncaughtExceptionHandler();
  14.     NSSetUncaughtExceptionHandler(&myExceptionHandler);
  15.     ….
  16. }

If you use several libraries that auto-install their own exception handlers, such as flurry + testflight + crittercism, you can use this proxying trick to get out of exception handling hell.

You may also want to consider the GTMStackTraceFromException function from the Google Toolbox For Mac to log a full stack trace.