Exception Message Service

You can implement an exception message service for resolving localized messages using error codes. The exception class uses the exception message service to load resource bundles and look up error messages based on an error code. You can use a default message provider, ExceptionMessageServiceImpl, or create a custom provider by implementing your own ExceptionMessageService.

To resolve localized messages, implement the ExceptionMessageService interface.

public class CustomExceptionMessageService implements ExceptionMessageService
{
  public String getMessage(int errorCode)
  {
    String msg = null;

    msg = "getMessage(" + errorCode + ")";

    return msg;
  }

  public String getMessage(int errorCode, String localeName)
  {
    String msg = null;

    msg = "getMessage(" + errorCode + "," + localeName + ")";

    return msg;
  }
}

A default implementation, ExceptionMessageServiceImpl allows the default English resource to look up an error message using an error code. You can follow these steps to add other localized resources for the BlackBerry platform without implementing a custom message service.

  1. Get the default resource package files (included in the resources folder in the Mobile SDK for the BlackBerry platform):
    • com/sybase/mobile/ErrorMessage.rrh
    • com/sybase/mobile/ErrorMessage_en.rrc
  2. Localize them to other language files, for example:
    • com/sybase/mobile/ErrorMessage.rrh
    • com/sybase/mobile/ErrorMessage_de.rrc
  3. Add the new resource files into the src folder of the application.
  4. Register the default implementation "ExceptionMessageServiceImpl" in the application code:
     ServiceRegistry.getInstance().registerService(ExceptionMessageService.class,
    ExceptionMessageServiceImpl.getInstance()); 
  5. The application uses the localized error message automatically.
  6. You can unregister the exception message service to cancel the use of the localized error message:
    ServiceRegistry.getInstance().unregisterService(ExceptionMessageService.class);