比如:
try{
$user = \App\User::find(1);
$user->email = $email;
$user->save();
return response()->json([ 'msg' => 'success']);
}catch( ??? ){
return response()->json([ 'msg' => 'error','d' => 捕获到的异常信息 ]);
}
我应如何写才能捕获到异常?
1
ZGLHHH OP |
2
yangqi 2016-07-19 23:31:17 +08:00
你这最常见的应该是 ModelNotFoundException
https://laracasts.com/discuss/channels/tips/a-list-of-most-common-laravel-errors-exceptions |
3
yangqi 2016-07-19 23:33:28 +08:00
@ZGLHHH QueryException 是通用 exception, 应该放到全局的 exception handler 里面。不然你每执行一次 query 都要 catch 然后 handle 一遍不是要累死。。。
|
5
yangqi 2016-07-19 23:42:42 +08:00
|
6
ZGLHHH OP |