php自定义异常 [英] php custom exceptions
本文介绍了php自定义异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道如何编写自定义异常处理程序。
I was wondering how would one go about writing custom exception handlers.
所以我可以做一些像
抛出新的dbException($ sql,$ message);
并输出
您的查询中出现错误
消息:{$ message here}
查询:{$ sql here}
行:{行异常被抛出}
文件:{文件异常被抛出}
There was an error in your query Message: {$message here}
Query: {$sql here}
Line: {line exception was thrown on}
File: {file exception was thrown from}
但我也想抓住例如语法错误和解析错误(如果可能)
but I also want to to catch eg syntax errors and parse errors (if possible)
推荐答案
嗯,你可以扩展异常
类但是你喜欢对于自定义例外,您可能需要查看以下信息:
Well, you can extend the Exception
class however you like. For custom exceptions, you might want to check out the post:
- PHP 5 OOP: Delegation and Custom Exceptions
你还应该发现这个线程很有用:
You should also find this thread useful:
- Custom Exception Messages: Best practices
这篇关于php自定义异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文