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 IExceptionMessageService interface.

class CustomExceptionMessageService : IExceptionMessageService
{
  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 without implementing a custom message service.

  1. Get the default file "SUPErrorMessage.en.txt" (included in the resources folder in the Mobile SDK for the Windows and Windows Mobile platform) and localize it to another language file such as "SUPErrorMessage.de.txt"
  2. Use "resgen.exe" to generate its resource file like "SUPErrorMessage.de.resources":
    >>resgen SUPErrorMessage.de.txt 
  3. Register the default implementation "ExceptionMessageServiceImpl" in the application code:
    ServiceRegistry.GetInstance().RegisterService(typeof(IExceptionMessageService),
          ExceptionMessageServiceImpl.GetInstance()); 
  4. Put the generated resource file into the same folder of the application execution file.
  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<IExceptionMessageService>(typeof(IExceptionMessageService));