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.
ServiceRegistry.getInstance().registerService(ExceptionMessageService.class, ExceptionMessageServiceImpl.getInstance());
ServiceRegistry.getInstance().unregisterService(ExceptionMessageService.class);