Re:PHP finally gets finally
by spdy on Monday August 13, 2012 @03:28PM
(#4377648)
Does it now catch system exceptions as well?
Something that drove me away from php that i was not able to catch all errors inside an exception block.
[ Parent
| on HN ]
I think this has been possible more or less since PHP introduced exceptions by using `set_error_handler`:
http://php.net/manual/en/function.set-error-handler.php
along with a function that throws exceptions, e.g.:
function exception_on_error($errnum,$errmsg) { throw new ErrorException($errmsg,$errnum); }
You can't catch all errors (sensibly including compile errors and unhandled exception errors), but it can get you pretty far.
Not that there aren't other reasons not to use PHP, but this one is manageable.