如何在Symfony 4中设置错误处理程序安全网?

PHP offers the possibility to set customer error handlers with set_error_handler("customError",E_USER_WARNING); (for example).

How and where can I set some default error handlers for a Symfony 4 application to make sure I catch all unhandled errors?

I have noticed the Debug component which mentions ErrorHandler::register();. Is this the safety net I am looking for? If yes, where should I put that error handler registration call in my code? Should I modify the index.php page?

In your index.php, you can use it like below:

$app->error(function (\Exception $e, $code) use ($app) {
    $errors = [
        [
            'status' => $code,
            'detail' => $e->getMessage()
        ]
    ];
    if ($app['debug'] === true) {
        $errors['file'] = $e->getFile();
        $errors['line'] = $e->getLine();
    }
    return new JsonResponse(['errors' => $errors]);
});

Do the kernel events may be a solution to your issue ?

http://symfony.com/doc/current/event_dispatcher.html

You can check out all requests made on your kernel or controllers and even stop propagation of them.