dongpengqin3898 2013-01-16 11:51
浏览 42
已采纳

在没有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 2013-01-16 12: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
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部