【发布时间】:2018-03-29 20:05:05
【问题描述】:
我正在使用 laravel 5.5 我编写了一个带有 try and catch 异常的代码。但是 Try/catch 不是管理异常处理。在Exception/handle.php 上执行异常
这是我正在关注的代码
try {
App\Models\justDoIt::find(1);
} catch (\Exception $ex) {
dd($ex);
report($ex);
return false;
}
我想知道为什么不执行 catch 并且在report() 中的handle.php 显示错误
这里是handle.php代码
public function report(Exception $exception) {
echo "Handle";
dd($exception);
parent::report($exception);
}
结果
Handle
FatalThrowableError {#284 ▼
#message: "Class 'App\Http\Controllers\App\Models\justDoIt' not found"
#code: 0
#file: "D:\xampp7\htdocs\homeexpert_nik\app\Http\Controllers\HomeController.php"
#line: 21
#severity: E_ERROR
trace: {▶}
}
结果将显示在 handle.php 文件中。
【问题讨论】:
-
你可以使用
JustDoIt::findOrFail -
@RutvijKothari 我尝试使用 FindOrFail 但我仍然从句柄中得到异常?为什么会这样?为什么不执行 catch Exception
-
Class not found 异常在 PHP 中的处理方式不同。您可以在这里找到更多信息:stackoverflow.com/questions/4421320/…
标签: laravel laravel-5 try-catch laravel-5.5