Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php custom exceptions

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

so that I can do something like

throw new 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)

like image 793
Hailwood Avatar asked Feb 15 '11 20:02

Hailwood


1 Answers

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
like image 69
Sarfraz Avatar answered Oct 04 '22 10:10

Sarfraz