note 82197 deleted from language.exceptions by bjori
| From: | bjori@php.net | Date: | Fri, 28 Nov 2008 17:34:20 +0000 |
| Subject: | note 82197 deleted from language.exceptions by bjori | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-147091@lists.php.net to get a copy of this message | ||
Note Submitter: Eli Sand
----
There's been a few pieces of code already to show how to convert normal PHP errors in to
exceptions, but if you want a simple single line you can put somewhere, try this:
<?php
set_error_handler(create_function('$x, $y', 'throw new Exception($y, $x);'));
?>
It doesn't get any easier than that. The only catch is this must be executed in the global
scope. That means you can't embed this in a class for example. Just add it near the beginning
of your entire script (where you include() files for example) and that should be it! Just make sure
to catch the exceptions thrown, or set a default exception handler.