I\'m trying to do the following:
try {
// just an example
$time = \'wrong datatype\';
$timestamp = date(\"Y-m-d H:i:s\", $time);
} catch (Ex
catch(Throwable $e) works
catch ( Throwable $e){
$msg = $e-> getMessage();
}
The shorter that I have found:
set_error_handler(function($errno, $errstr, $errfile, $errline ){
throw new ErrorException($errstr, $errno, 0, $errfile, $errline);
});
Makes all errors becoming instance of catchable ErrorException
try {
// call a success/error/progress handler
} catch (\Throwable $e) { // For PHP 7
// handle $e
} catch (\Exception $e) { // For PHP 5
// handle $e
}
Use ErrorException to turn errors into exceptions to handle:
function exception_error_handler($errno, $errstr, $errfile, $errline ) {
throw new ErrorException($errstr, $errno, 0, $errfile, $errline);
}
set_error_handler("exception_error_handler");
try {
// just an example
$time = 'wrong datatype';
if (false === $timestamp = date("Y-m-d H:i:s", $time)) {
throw new Exception('date error');
}
} catch (Exception $e) {
return false;
}