How to do application level exception handling in iPhone app

I am working on an application for processing some images. If something goes wrong, the application crashes. I want to avoid such scenarios. When any exception occurs at any stage of the application, I want to handle it and provide the user with a friendly message. In C #, an application for creating windows, this can be done, but for the iPhone I am new and, therefore, do not know any way to achieve it.

Can anyone help me on this.

thanks

Ashwani

+3
source share
3 answers

You can implement an opaque exception handler that matches this signature:

typedef volatile void NSUncaughtExceptionHandler(NSException *exception);

NSSetUncaughtExceptionHandler. , , ( mailto: url, - , ITunes 8.2 ).

EDIT: , , . , , , , . , - . Apple:

, .

+5
@try {
  //Code on which you want to put the check
}
@catch (NSException *exception){
  //This finds out which kind of exception it is.
  NSLog(@"main: Caught %@: %@", [exception name], [exception reason]);
}
@finally {
  //This piece of code executes no matter whether an exception occured or not.
}

: Iphone

+1
void UncaughtExceptionHandler(NSException *exception)
{
   @try
{
     UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"App Committed Suicide"
                                                    message:@"Oh dear, that wasn't supposed to happen. You will have to restart the application... sorry!"
                                                   delegate:[[UIApplication sharedApplication] delegate] cancelButtonTitle:nil otherButtonTitles:@"That ok!", @"Erm, bye...", nil];
    [alert show];
    [alert release];
    while (exceptionAlertDismissed == FALSE)
    {
        [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
    }
}
@catch (NSException *exception)
{

}
@finally
{
    @throw exception;
}
}  

- NSSetUncaughtExceptionHandler, ,   appDelegate.m file NSSetUncaughtExceptionHandler (& UncaughtExceptionHandler); FinishLaunchingWithOptions
, , .

+1

Source: https://habr.com/ru/post/1710235/


All Articles