title: No exception stacktrace in console under Xcode 4.2/iOS 5?
body: <p>Under Xcode 3.x and iOS 4, if an unhandled exception is signaled in the emulator there is an exception stack trace (similar to Java's) produced in the console output.</p>
  <p>When I raise an unhandled exception in iOS 5 under Xcode 4.2, running the exact same app code, the stack trace does not occur.  (I did figure out how to set an exception breakpoint, but that doesn't produce the traceback in the console.)</p>
  <p>Is this merely an Xcode setting I need to make somewhere, or a &quot;feature&quot; of Xcode 4/iOS 5?  Is there some way restore this bit of functionality?</p>
  <h2>Update</h2>
  <p>Unfortunately, adding an <code>uncaughtExceptionHandler</code> doesn't work.  Here is the handler:</p>
  <pre><code>void uncaughtExceptionHandler(NSException *exception) {
      NSLog(@&quot;uncaughtExceptionHnadler -- Exception %@&quot;, [exception description]);
      // Because iOS 5 doesn't provide a traceback, provide one here
      NSLog(@&quot;Stack trace: %@&quot;, [exception callStackSymbols]);
      // Let Flurry look at the error
      [FlurryAPI logError:@&quot;Uncaught&quot; message:@&quot;Crash!&quot; exception:exception];
  }                                               
  </code></pre>
  <p>(It turns out it was already present, to do the Flurry thing, so I just added the stack trace.)</p>
  <p>Here is where it's enabled (just a few lines below where the handler is declared):</p>
  <pre><code>- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
      
      // Enable uncaught exception handler to dump stack and let Flurry log the exception
      NSUncaughtExceptionHandler* hdlr = NSGetUncaughtExceptionHandler();
      NSSetUncaughtExceptionHandler(&amp;uncaughtExceptionHandler);
      NSUncaughtExceptionHandler* newHdlr = NSGetUncaughtExceptionHandler();
      
      // TODO: Test
      NSException* ex = [NSException exceptionWithName:@&quot;AssertionFailure&quot; reason:@&quot;Test&quot; userInfo:nil]; 
      @throw ex; 
  </code></pre>
  <p>I set breakpoints to enable me to check the two retrieved handler values.  The first one is nil and the second is an apparently valid address.  But when the test exception is thrown the handler (in iOS 5 simulator) never gets control.  (Though when I run on the iOS 4.2 simulator it does get control.)</p>
  <p>Setting <code>NSExceptionHandlingMask</code> is apparently not possible on iPhone.  The prereq <code>ExceptionHandling.framework</code> is not available.</p>
  <h2>Update 2</h2>
  <p>This works:</p>
  <pre><code>int main(int argc, char *argv[]) {
      
      NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
      int retVal = -1;
      @try {
          retVal = UIApplicationMain(argc, argv, nil, nil);
      }
      @catch (NSException* exception) {
          NSLog(@&quot;Uncaught exception: %@&quot;, exception.description);
          NSLog(@&quot;Stack trace: %@&quot;, [exception callStackSymbols]);
      }
      [pool release];
      return retVal;
  }
  </code></pre>