【发布时间】:2015-07-08 12:40:39
【问题描述】:
我正在构建一个网关,以使应用程序的多个实例能够相互通信。为了连接到不同的数据库,我使用了 Laravel 的 Capsule。
当对数据库的请求失败时,我想记录错误,但由于某种原因,我无法正确捕获异常。查看日志,捕获正在运行,但之后应用程序仍在死亡。
代码非常基本:
try {
// connection and request here
} catch (PDOException $e) {
Log::error('*************************************************************************');
Log::error('Failure reading franchise BDCs');
Log::error('Franchise: '.json_encode($franchise->site_url));
Log::error('*************************************************************************');
}
在日志中我有以下内容:
[2015-04-29 09:46:35] production.INFO: 开始阅读 PPFD [] []
[2015-04-29 09:46:35] 生产。错误:
**************************************************** ****************************** [] []
[2015-04-29 09:46:35] production.ERROR:读取特许经营 BDC 失败 [] []
[2015-04-29 09:46:35] production.ERROR: Franchise: "https://ppfd.domain.net/" [] []
[2015-04-29 09:46:35] 生产。错误:
**************************************************** ****************************** [] []
[2015-04-29 09:46:35] production.ERROR: 异常 'PDOException' 带有消息 'SQLSTATE[HY000] [1045] 用户 'test'@'pp.damain.net' 的访问被拒绝(使用密码:YES)' 在 /var/www/fd/releases/20150423164018/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:47
堆栈跟踪:
我怎样才能捕捉到这个异常并让代码继续运行而不是崩溃?
提前致谢。任何帮助表示赞赏。
【问题讨论】:
-
Laravel 4.1,从未考虑升级该特定应用程序
标签: php database exception laravel exception-handling