Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8476229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:07:20+00:00 2026-06-10T18:07:20+00:00

Under Xcode 3.x and iOS 4, if an unhandled exception is signaled in the

  • 0

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.

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.)

Is this merely an Xcode setting I need to make somewhere, or a "feature" of Xcode 4/iOS 5? Is there some way restore this bit of functionality?

Update

Unfortunately, adding an uncaughtExceptionHandler doesn’t work. Here is the handler:

void uncaughtExceptionHandler(NSException *exception) {
    NSLog(@"uncaughtExceptionHnadler -- Exception %@", [exception description]);
    // Because iOS 5 doesn't provide a traceback, provide one here
    NSLog(@"Stack trace: %@", [exception callStackSymbols]);
    // Let Flurry look at the error
    [FlurryAPI logError:@"Uncaught" message:@"Crash!" exception:exception];
}                                               

(It turns out it was already present, to do the Flurry thing, so I just added the stack trace.)

Here is where it’s enabled (just a few lines below where the handler is declared):

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    // Enable uncaught exception handler to dump stack and let Flurry log the exception
    NSUncaughtExceptionHandler* hdlr = NSGetUncaughtExceptionHandler();
    NSSetUncaughtExceptionHandler(&uncaughtExceptionHandler);
    NSUncaughtExceptionHandler* newHdlr = NSGetUncaughtExceptionHandler();
    
    // TODO: Test
    NSException* ex = [NSException exceptionWithName:@"AssertionFailure" reason:@"Test" userInfo:nil]; 
    @throw ex; 

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.)

Setting NSExceptionHandlingMask is apparently not possible on iPhone. The prereq ExceptionHandling.framework is not available.

Update 2

This works:

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(@"Uncaught exception: %@", exception.description);
        NSLog(@"Stack trace: %@", [exception callStackSymbols]);
    }
    [pool release];
    return retVal;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T18:07:22+00:00Added an answer on June 10, 2026 at 6:07 pm

    This works:

    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(@"Uncaught exception: %@", exception.description);
            NSLog(@"Stack trace: %@", [exception callStackSymbols]);
        }
        [pool release];
        return retVal;
    }
    

    For ARC:

    int main(int argc, char *argv[]) {
    
        int retVal = -1;
        @autoreleasepool {
            @try {
                retVal = UIApplicationMain(argc, argv, nil, nil);
            }
            @catch (NSException* exception) {
                NSLog(@"Uncaught exception: %@", exception.description);
                NSLog(@"Stack trace: %@", [exception callStackSymbols]);
            }
        }
        return retVal;
    }
    

    Still waiting for some sort of explanation as to why the default dump no longer works and/or why (even more serious) uncaughtExceptionHandler doesn’t work. However, apparently this problem only affects the emulator.

    update:

    It has been pointed out that if you go to Product -> Scheme -> Edit Scheme, select "Run (Debug)", select the "Diagnostics" tab, and click "Log Exceptions", this will restore the missing Xcode default exception logging, possibly (I haven’t tried it yet) eliminating the need for the above hack.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a XCode which builds and runs under XCode. I would like to
I am trying to use XMPPFramework with an iOS5 project (ARC) under xcode 4.2.1
I can find the tool command in my filesystem under: /Applications/Xcode.app/Contents/Developer/usr/bin/otool If I specify
I've an app using low level CoreAudio C functions, usually located under /Volumes/Xcode/Xcode.app/Contents/Developer/Extras/CoreAudio/PublicUtility/. Just
In Xcode 3.2.1 on Mac OS X Snow Leopard, I open a project under:
Under the .NET Compact Framework, there is no FormWindowState.Minimize value. How can I minimize
I'm developing an iOS app with XCode 4.2 and latest SDK. I have added
I have a problem with the phonegap version 1.7.0rc1 and the development under iOS
In Xcode I have edited the scheme for the iOS device, and changed the
Possible Duplicate: Bug with starting Instruments via Profile under XCode 4.1 Build 4B110 Instruments

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.