AbstractObject::exception PHP Method

exception() public method

Returns relevant exception class. Use this method with "throw".
public exception ( string $message = 'Undefined Exception', string $type = null, string $code = null ) : BaseException
$message string Static text of exception.
$type string Exception class or class postfix
$code string 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;
    }