In Symfony 3.x, this is how it can be done:
To services.yml, add the listener override (as in @Ziumin's answer):
services:
twig.exception_listener:
class: stdObject
In app_dev.php, comment out the line Debug::enable();
, which will disable even the simplified error handling page (and then there's no need to modify files from the framework).
Then after that, you can add your own exception handler:
// Disable error handling page:
// Debug::enable();
set_exception_handler(function($e) {
$msg = array();
$msg[] = 'Exception: ' . $e->getMessage() . ' at ' . $e->getFile() . ':' . $e->getLine();
$msg[] = '';
$msg[] = $e->getTraceAsString();
echo implode("\n", $msg);
});