PHP.nl

Converting error reporting to exceptions

Opmerking: > Internal PHP functions mainly use , only modern

 extensions use exceptions. However, errors can be easily translated to
 exceptions with .
 This technique only works with non-fatal errors, however.
Error reportingObject-orientedErrorException

Voorbeeld: Converting error reporting to exceptions

<?php
function exceptions_error_handler($severity, $message, $filename, $lineno) {
    throw new ErrorException($message, 0, $severity, $filename, $lineno);
}

set_error_handler('exceptions_error_handler');
?>

Tip: > The provides a good number of . Standard PHP Library (SPL)built-in exceptions