0

I want to integrate in my iPad application a way to monitor the user activity and especially the exceptions that occurred and triggered the application to stop, something like the bug report of Apple but for the mobile clients.

I tried to encapsulate the main action (main.m) between @try and @catch blocks, but the exception is not thrown until there, and I just can't add such blocks everywhere in my code. Neither the delegate method applicationWillTerminate is not called, the application is just brutally stopped without any notification.

Any ideas on this ?

Ossir
  • 3,109
  • 1
  • 34
  • 52
  • The solution presented at < [link](http://stackoverflow.com/questions/1282364/how-do-you-implement-global-iphone-exception-handling) > resolved my situation. In the indicated response, only the **Approach1** and **Approach2** did worked for me. Can't understand why the above example similar to the one I've tried does not work, it should be the same as a unhandled exception handler. – user2822899 May 29 '14 at 14:50

1 Answers1

0

It works for me in main.m

int main(int argc, char *argv[]) {
    @autoreleasepool { 
        int retVal = 0;
        @try {
            retVal = UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
        }
        @catch (NSException *exception) {
            NSLog(@"Exception: %@", exception);
            [exception raise];
        }

        return retVal;    
    }
}

P.S.

Another tricky way : EXC_BAD_ACCESS automatic handling

And example of NSUncaughtExceptionHandler

Community
  • 1
  • 1
Ossir
  • 3,109
  • 1
  • 34
  • 52
  • 2
    Imagine the following scenarios: add 'nil' into a mutable array or try to access a non-exiting index in an array. This is not so unusual situations, might be a controller or element that in a some kind of situation it is invalid and not present, therefore the exception thrown will not be caught by the application not even instead of NSException a NSError is used. The application will just be stopped without any notification. – user2822899 May 29 '14 at 13:56
  • You're right, totally forgot about `NSSetUncaughtExceptionHandler` – Ossir May 30 '14 at 05:26
  • Is better than nothing in lack of a better solution. – user2822899 May 30 '14 at 11:56