Example Code for Handling Exceptions

An example of registering your interface.

defaultMessageProvider = [SUPExceptionMessageDefaultProvider getInstance];

// register a custom message provider
SUPServiceRegistry* sr = [SUPServiceRegistry getInstance];
[sr registerService:@protocol(SUPExceptionMessageProvider) withImplementation:defaultMessageProvider];

You can retrieve error codes using the errorCode property of SUPBaseException:

@try 
{
  // …
}
@catch (SUPBaseException *e) 
{
    if(e.errorCode != ERR_APP_NOT_REGISTERED)
    {
  }
}

To retrieve the error message using the preferred language for the device:

@try 
{
  // …
}
@catch (SUPBaseException *e) 
{
  NSString* errorMessage = e.message;
}

To retrieve the error message for a specific language:

@try 
{
  // …
}
@catch (SUPBaseException *e) 
{
  NSString* errorMessageSpanish = [e messageWithLocale:@"es"];
}

You can catch exceptions using the built-in support in Objective-C. The object can be either a SUPBaseException object or a subclass of the SUPBaseException object such as the SUPPersistenceException object.

@try 
{
  [self CallMethodThatMightThrowException];
}
@catch (SUPPersistenceException *e) 
{
  // this will catch all SUPPersistenceException type objects
}
@catch (SUPBaseException *e) 
{
  // this will catch all other SUPBaseExcepiton type objects
}
@finally
{
  // finally block…
}