1
我正嘗試使用自定義參數創建自定義異常。我覺得我在這裏做錯了事。基本上我想處理Laravel的異常處理文件中的異常,但我需要額外的數據,例外情況是要知道是誰引起異常。這是我到目前爲止...Laravel 5.1自定義異常的自定義參數
<?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傳遞到異常,以便我可以稍後訪問它。但我有問題。在這種情況下,我不知道要通過什麼作爲「$前一個」變量...
throw new ApiException($user->id, 'im testing', 200, $previous);
任何幫助將不勝感激。