I am playing with try - catch
block:
There might be some fatal errors which are not even caught by set_error_handler()
or \Throwable
.
The below implementation will catch the errors which are not even caught by \Throwable
as tested in php 7.1. It should only be implemented in your development environment(by just adding it in your development config file) and shouldn't be done in production.
Implementation
register_shutdown_function(function () {
$err = error_get_last();
if (! is_null($err)) {
print 'Error#'.$err['message'].'
';
print 'Line#'.$err['line'].'
';
print 'File#'.$err['file'].'
';
}
});
Example Error
Error# Class Path/To/MyService contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Path/To/MyServiceInterface::add)
Line# 12
File# Path/To/MyService.php