Я хочу отправить свои собственные параметры в настраиваемое исключение, используя throw new CustomException.
Я определил свои коды ошибок в Config, и они мне необходимы.
public function saveMenu($data){
$validatedData = Validator::make($data, array(
'id' => 'required',
'menuID' => 'required',
));
try {
$validatedData->validate();
} catch \Exception $e){
$data= array(
'status' => false,
'code' => 599
'message' => config('exception_codes.599').'<br/>'.$validatedData->errors(),
'data' => []
);
throw new CustomException($data ['message'], $data['code'],$e);
return $data;
}
}
class Handler расширяет ExceptionHandler {
protected $dontReport = [
//
];
protected $dontFlash = [
'password',
'password_confirmation',
];
public function report( Exception $exception=NULL)
{
parent::report($exception);
}
public function render($request, Exception $exception)
{
return parent::render($request, $exception);
}
}
class CustomException extends Exception{
public $code;
public $message;
public $trace;
public function __construct( $message, $code, Exception $exception=NULL)
{
parent::__construct($message, $code, $exception);
$this->code = $code;
$this->message=$message;
$this->trace= $exception->getTrace();
}
public function report($message, $code, Exception $exception=NULL)
{
$message = $exception->getMessage();
$xx= new Menu();
$xx->setFile($this->trace[1]['file']);
$xx->setLine($this->trace[1]['line']);
$xx->setFunction($this->trace[1]['function']);
$xx->setClass($this->trace[1]['class']);
$xx->setMessage($message);
$xx->save();
parent::report($exception);
}
public function render($request, Exception $exception)
{
return parent::render($request, $exception);
}
Я получаю эту ошибку;
Too few arguments to function App\Exceptions\CustomException::report(), 0 passed in C:......\Handler.php on line 102 and at least 2 expected"
Можешь мне помочь?






Нет необходимости явно передавать сообщение и код в методе report().
public function report()
{
$message = $this->getMessage();
$hataTakip = new HataTakip();
$hataTakip->setFile($this->trace[1]['file']);
$hataTakip->setLine($this->trace[1]['line']);
$hataTakip->setFunction($this->trace[1]['function']);
$hataTakip->setClass($this->trace[1]['class']);
$hataTakip->setMessage($message);
$hataTakip->save();
parent::report($this);
}
В любом случае вам следует ознакомиться с документацией на Обработка ошибок.
он говорит, что вызов неопределенного метода Exception :: report () @Mozammil