/**
* Returns relevant exception class. Use this method with "throw".
*
* @param string $message Static text of exception.
* @param string $type Exception class or class postfix
* @param string $code Optional error code
*
* @return BaseException
*/
public function exception($message = 'Undefined Exception', $type = null, $code = null)
{
if ($type === null) {
$type = $this->default_exception;
} elseif ($type[0] == '_') {
if ($this->default_exception == 'BaseException') {
$type = 'Exception_' . substr($type, 1);
} else {
$type = $this->default_exception . '_' . substr($type, 1);
}
} elseif ($type != 'BaseException') {
$type = $this->app->normalizeClassName($type, 'Exception');
}
// Localization support
$message = $this->app->_($message);
if ($type == 'Exception') {
$type = 'BaseException';
}
$e = new $type($message, $code);
if (!$e instanceof BaseException) {
throw $e;
}
$e->owner = $this;
$e->app = $this->app;
$e->api = $this->app;
// compatibility with ATK 4.2 and lower
$e->init();
return $e;
}