As of PHP 7.4, an exception thrown within the user-defined shutdown function can be caught by the user-defined exception handler.
<?php
set_error_handler(
function($level, $error, $file, $line){
if(0 === error_reporting()){
return false;
}
throw new ErrorException($error, -1, $level, $file, $line);
},
E_ALL
);
register_shutdown_function(function(){
$error = error_get_last();
if($error){
throw new ErrorException($error['message'], -1, $error['type'], $error['file'], $error['line']);
}
});
set_exception_handler(function($exception){
});
require 'NotExists.php';