laravel Error Class ‘App\Http\Controllers\Exception’ not found

2020-03-25 18:36   Tags:

问题

throw new Exception('ok');

解决

用这个php自带的\Exception

throw new \Exception("ok");
try {

    throw new \Exception('ok');

} catch (\Exception $e) {

    echo $e->getMessage();

}

或者

先在类前面引入use Exception

use Exception;
try {

    throw new Exception('ok');

} catch (Exception $e) {

    echo $e->getMessage();

}

参考:

https://stackoverflow.com/questions/41415095/exception-class-not-found-in-laravel

发表评论

电子邮件地址不会被公开。 必填项已用*标注