dongpengqin3898 2013-01-16 19: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 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
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 一道python难题
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度