dongye1912 2010-04-01 14:48
浏览 34

最好的PHP错误类

I am looking for some coding ideas on the following task I am trying to achive.

I have a list of Error Numbers, Description, and User Friendly Description in a document.

Ex:
Error Number, Description, User Friendly Description 
-----------------------------------------------------
1, Internal Error, "An Internal Error has occurred. Please try again later".
2, Delete Failed, "Unable to delete an Entry. Please try later".

I want to write a PHP class to store all the above in such a fashion that I can access them later with ease when an error occurs in the code..

Ex: If my code received an error 2, I want to check that error code with the list of error codes in the class, retrieve the description, user friendly description and display it to the user.

I want this to be of minimum overhead. So, don't want to store it in database.

I am using PHP5 with Zend MVC framework. Anybody can help me with the best possible sample code?

Thanks

  • 写回答

2条回答 默认 最新

  • douxiong5438 2010-04-01 14:54
    关注

    I like to use a simple custom error handler and custom exception handler that do the following:

    If in development mode:

    • Show the detailed error message

    • If E_WARNING or worse, output error message into a log file (e.g. using Zend_Log)

    • If a fatal error, halt execution and show a nice error page with a full backtrace

    If in production mode:

    • Only log error messages

    • On fatal errors, halt execution and show a nice "an error has occurred" page only.

    I like working with errors, so any exception I catch I call a trigger_error() for to do the output and logging.

    You can also extend the default Exception class to do the logging and display. You would want to turn any error that occurs into exceptions. Manual errors you would then trigger as exception using throw.

    Inspiration:

    Kohana's Error Handler (Screenshot here) is the nicest and greatest I've seen to date. It's open source, maybe you can even grab out that part (make sure you read the license first, though.)

    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?