开发者

php custom exceptions

开发者 https://www.devze.com 2023-02-11 04:24 出处:网络
I was wondering how would one go about writing custom exception handlers. so that I can do something like

I was wondering how would one go about writing custom exception handlers.

so that I can do something like

throw n开发者_高级运维ew dbException($sql, $message);

and have it output

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


Unless I am misunderstanding your question, you should be able to extend PHP's Exception class.


Why don't use just write your own exception class derived from the standard base exception? See extending exceptions manual.

0

精彩评论

暂无评论...
验证码 换一张
取 消