Exceptions and Localization

LangException class

Extension for PHP standard Exception with an extra LangText parameter, typical use case sending messages to users too.

This documentation refers to SuiteCRM version 7.10.3 onwards

Usage

try {

  // throw new LangException with located exception message:
  thow new LangException(
    'Exception message for developers', EXCEPTION_CODE, null,
    new LangText('LBL_TRANSLATABLE_USER_MESSAGE'));

} catch (LangException $e) {

  // using logger to inform the developer about the exception
  $log = LoggerManager::getLogger();
  $log->fatal('Exception happend in the example: ' . $e->getMessage() . ', code: ' . $e->getCode());

  // using SugarApplication to inform the user about the problem with translated message:
  SugarApplication::appendErrorMessage($e->getLangMessage());
}

Content is available under GNU Free Documentation License 1.3 or later unless otherwise noted.