I am trying to create a custom exception with a custom parameter in it. I feel like I am doing something wrong here. Basically I would like to handle the exception in Laravel's exception handling file but I need extra data with the exception to know things like who caused the exception. This is what I have so far...
<?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;
}
}
The idea here was to pass the userId into the exception so I can access it later. But I am having a problem. In this case, I don't know what to pass in as the "$previous" variable...
throw new ApiException($user->id, 'im testing', 200, $previous);
Any help would be greatly appreciated.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire