nicklasos
9/30/2014 - 2:42 PM

Convert php errors to exceptions

Convert php errors to exceptions

<?php
set_error_handler(function ($errNo, $errStr, $errFile, $errLine ) {
    throw new \ErrorException($errStr, 0, $errNo, $errFile, $errLine);
});

try {
    echo 5 / 0;
} catch (ErrorException $e) {
    echo 'Got error: ' . $e->getMessage();
}