dongli8862 2017-12-06 09:33
浏览 831

Yii2 - 错误处理程序无法捕获数据库异常

I'm working on Yii2 advanced application project and I have a problem with yii2 built-in Error Handler. Here is description of my problem:

I have set errorAction in my backend configuration in this way:

'errorHandler' => [
    'errorAction' => 'site/error',
],

Now, the method actionError() in the SiteController catches every application exceptions, user defined exceptions and also fatal errors, except database related exception such as yii\db\IntegrityException. I don't know why, but when such an exception occurs, actionError() does not do anything! I don't want to catch exception manually with try-catch block and I want the central ErrorHandler catches all exception.

How can I fix this problem? Thank you all specially yii experts for paying attention. Please help me to solve this strange problem.

  • 写回答

1条回答 默认 最新

  • dongpu2694 2017-12-06 12:27
    关注

    According to this GitHub issue: yiisoft/yii2/issues/10657 and to the comment made by @Yupik you must change the YII_DEBUG.

    If YII_DEBUG is true, you should see proper message about yii\db\IntegrityException in debug mode.

    If YII_DEBUG is false(like in a production enviroment) error is redirected to actionError() and see it in a user-friendly mode.

    评论

报告相同问题?

悬赏问题

  • ¥15 聚类分析或者python进行数据分析
  • ¥15 如何用visual studio code实现html页面
  • ¥15 逻辑谓词和消解原理的运用
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?