Home | About Me
| | | | | | | | | |

Symfony 3: Error Handling

Hands-On | 14 Mar 2019
Tags:


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 %}
  

Page not found.

{{ status_text }}, {{status_code}}

{% endblock %}