php - 我该如何处理流明异常?
问题描述
我想在发生错误时记录错误。
我的控制器是这样的:
try {
Wallet::create([
'name' => 'TET',
]);
} catch (QueryException $e) {
$message = Str::contains($e->getMessage(), 'Deadlock') ? 'Server is busy' : $e->getMessage();
throw new HttpException(400, $message);
} catch (\Exception $e) {
throw new HttpException(400, $e->getMessage());
}
我的 App\Exceptions\Handler.php 是这样的:
public function report(Throwable $exception)
{
if ($exception instanceof QueryException) {
Log::error($exception->getMessage());
}
parent::report($exception);
}
但异常不是 QueryException 的 instanceof。
解决方案
推荐阅读
- sql - FAILED: SemanticException Line 0:-1 Unsupported SubQuery Expression yyyy-MMM-dd: 只允许作为顶级连接的子查询表达式
- reactjs - .Net 核心和 React uppy.io 110mb 文件上传异常“请求内容意外结束”。
- node.js - $lookup 查找数组中的 ObjectId 并将其投影到同一个数组
- powershell - 如何修改这个 PowerShell 脚本?
- mysql - 在子查询中使用基表的字段不起作用
- mongodb - MongoDB 集合架构和数据模型
- amazon-web-services - AWS - 识别 Lambda 从 DynamoDB 流中读取的数据
- php - I am looking for a way to compare months in PHP
- angular - 更改参数而不更改订阅
- javascript - 使用 Javascript 使用选择选项重新编号动态表单集后,选定的选项将被删除