Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

When using CodeRunner to test Objective-C code snippets, any exception thrown during run time will cause a crash, followed by the <my program> quit unexpectedly alert with complete stack trace and crash report saved in ~/Library/Logs/DiagnosticReports.

The exception can for instance be the result of a misspelled method name, and can happen quite often, depending on your personal development style. It is worth noticing that this crash report is also sent to Apple, which can seem a bit excessive for a misspelled method name.

Can this alert and crash report be avoided?

share|improve this question

1 Answer 1

The default code template can be changed for each programming language in the app's Preferences settings.

If a try-catch block is added, the snippet can catch all its own exceptions and for instance just print out a log statement, hence avoiding the crash report.

For Objective-C, it can look like this:

#import <Foundation/Foundation.h>

int main(int argc, char *argv[]) {
    @autoreleasepool {
    @try {

    %@

    } @catch (NSException *e) {
        NSLog(@"Exception caught: %@", e);
    }
    }
}

The %@ defines the initial insertion point when a new file is opened.

share|improve this answer
    
That'll only work for thrown exceptions, not for hard crashes. –  bbum Jun 29 '13 at 17:13
1  
That's true, and thanks for pointing it out! For the code snippets that I typically compile and run in CodeRunner I only ever get thrown exceptions, though. Typically the misspelled method name mentioned above, for which a complete crash report sent to Apple also seems a bit excessive, not to mention the UX issue having to deal with the alert. Edited the title to reflect your comment. –  Monolo Jun 29 '13 at 19:13

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.