为什么我的异常没有被Laravel销毁方法捕获?

为什么我的异常没有被Laravel销毁方法捕获?,laravel,destroy,Laravel,Destroy,为什么我的异常没有被捕获 try { \Account::destroy($id); return Redirect::to("/manager/account") ->with("success_message", "Item excluido com sucesso"); } catch (Exception $e) { return Redirect::to("/m

为什么我的异常没有被捕获

    try {
        \Account::destroy($id);
        return Redirect::to("/manager/account")
                            ->with("success_message", "Item excluido com sucesso");
    } catch (Exception $e) {
        return Redirect::to("/manager/account/{$id}/edit")
                        ->with("error_message", "Erro ao excluir item");
    }
SQLSTATE[23000]:完整性约束冲突:1451无法删除或删除 更新父行:外键约束失败 (
imob\u io
users
,约束
users\u account\u id\u foreign
外键 (
account\u id
)引用
accounts
id
)(SQL:delete from
账户
其中
id
=2)


当前,您正在当前命名空间内捕获类
异常。相反,您应该参考全局类型
\Exception

catch (\Exception $e){
    return Redirect::to("/manager/account/{$id}/edit")
                    ->with("error_message", "Erro ao excluir item");
}
我还建议您缩小范围,而不是只捕获每个异常。例如,您可以捕获
QueryException
,它将因违反约束而抛出

catch(\Illuminate\Database\QueryException $e)

尝试捕捉
\Exception
而不是
Exception
哎哟。。。。!!名称空间!!谢谢