dongpengqin3898
2013-01-16 19:51 阅读 19
已采纳

在没有Try and Catch的情况下获取PDO错误

Hopefully I can say this in a way that makes sense..

I am learning PDO, and I am wanting to, at the footer.php file, make some kind of code that checks for PDO errors in the page.

In other words, I am wanting to set the error mode to ERRMODE_SILENT and at the end of the page, get all the PDO errors without adding the try and catch to every single query.

I'm not sure if this is even possible and not sure exactly how to Google that.

Any thoughts or suggestions?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    dongxin8392 dongxin8392 2013-01-16 20:54

    3 things about error reporting you need to know

    1. Most of time errors are fatal for the application and it is useless to continue.
      In this case no pages nor page bottoms to be executed but a generic 503 error page to be shown.
      To handle errors this way - just put one application-wide try-catch block at the very top and very bottom of script and set appropriate exception handler.
    2. Some errors are not fatal. To catch these you have to wrap your not-so-important code into local try-catch, catch the error and then continue execution.
    3. Instead of bottom of the page, you have to collect all your errors in the error log Set appropriate error handler for this
    点赞 评论 复制链接分享

相关推荐