Example Code for Handling Exceptions

An example of registering your interface.

// Register ExceptionMessageServiceImpl
ServiceRegistry.GetInstance().RegisterService(typeof(Sybase.Mobile.Framework.IExceptionMessageService), ExceptionMessageServiceImpl.GetInstance());
try
{
  // throw Sybase.Persistence.ObjectNotFoundException
}
catch (ObjectNotFoundException e)
{
  if (e.ErrorCode == ObjectNotFoundException.VALUE_IS_NULL)
  {
    string msg = e.Message;
    msg = e.GetLocalizedMessage("fr");
    msg = e.GetLocalizedMessage("es");
    msg = e.GetLocalizedMessage("de");
  }
}

// Register CustomExceptionMessageService
ServiceRegistry.GetInstance().RegisterService(typeof(Sybase.Mobile.Framework.IExceptionMessageService), new CustomExceptionMessageService());
try
{
  // throw Sybase.Persistence.ObjectNotFoundException
}
catch (ObjectNotFoundException e)
{
  if (e.ErrorCode == ObjectNotFoundException.VALUE_IS_NULL)
  {
    string msg = e.Message;
    msg = e.GetLocalizedMessage("fr");
    msg = e.GetLocalizedMessage("es");
    msg = e.GetLocalizedMessage("de");
  }
}
finally
{
  // Unregister CustomExceptionMessageService
  ServiceRegistry.GetInstance().UnregisterService<Sybase.Mobile.Framework.IExceptionMessageService>(typeof(Sybase.Mobile.Framework.IExceptionMessageService));
}