我正在尝试创建一个带有自定义参数的自定义异常。我觉得我在这里做错了什么。基本上,我想在Laravel的异常处理文件中处理异常,但我需要额外的数据来知道诸如谁引起了异常之类的事情。到目前为止,这就是我所拥有的...
<?php
namespace App\Exceptions;
use Exception;
class ApiException extends \Exception
{
public $userId;
public function __construct($userId, $message, $code, Exception $previous)
{
parent::__construct($message, $code, $previous);
$this->userId = $userId;
}
}
这里的想法是将userId传递到异常中,以便稍后可以访问它。但我遇到了一个问题。在这种情况下,我不知道该传递什么作为"$previous"变量...
throw new ApiException($user->id, 'im testing', 200, $previous);
任何帮助都将不胜感激。