我收到错误
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; }
}
任何帮助将不胜感激
答案 0 :(得分:0)
请阅读有关异常层次结构的信息-https://www.php.net/manual/en/class.exception.php 如错误所示,您的类ShopException需要实现Throwable接口。 您还可以从实现Throwable的标准异常类之一继承。 如果使用名称空间,则必须在异常类名称之前添加反斜杠“ \”。
class ShopException extends \Exception { ...}