Symfony 3: Error Handling

throw new NotFoundHttpException('Post not found');

This exception will be handled using default exception handler, which will try to locate a template from twig-bundle/Resources/views/Exception/error...html.twig.

It will first try to locate a template using the following order:

error[error_code].html.twig
error.json.twig
error.html.twig

These templates can be customized when mimic the structure of the bundle templates.

{# templates/bundles/TwigBundle/Exception/error404.html.twig #}
{% extends 'base.html.twig %}
{% block body %}
  <h1>Page not found.</h1>
  <p>{{ status_text }}, {{status_code}}</p>
{% endblock %}