PHP致命错误:无法抛出未实现Throwable的对象

时间:2018-01-21 05:33:39

标签: php exception exception-handling throw

我收到错误

  

PHP致命错误:未捕获错误:无法抛出未实现Throwable的对象

我正在尝试抛出异常

if ($err){ 
    throw new ShopException($err, $errno);
}

和处理

的异常类
class ShopException{
    protected $error;
        protected $errno;
    function __construct($error,$errno)
        {
            $this->error= $error;
            $this->errno= $errno;


        }
        function geterror() { return $this->error; }

 }

任何帮助将不胜感激

1 个答案:

答案 0 :(得分:0)

请阅读有关异常层次结构的信息-https://www.php.net/manual/en/class.exception.php 如错误所示,您的类ShopException需要实现Throwable接口。 您还可以从实现Throwable的标准异常类之一继承。 如果使用名称空间,则必须在异常类名称之前添加反斜杠“ \”。

class ShopException extends \Exception { ...}