Excepciones en PHP al estilo java

4 Comments // Written on May 01, 2008 // PHP, Programación

Un truco interesante para emular las excepciones de java en php.

set_error_handler(’error_handler’);
function error_handler($errno, $errstr, $errfile, $errline) {
if (4096 == $errno) throw new Exception($errstr);
return false;
}

Y después:

try {
// Operación que produce error
} catch (ErrorException $e) {
// Tratar el error
}