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

报告相同问题?

悬赏问题

  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?