如何在 Symfony 的自定义错误页面中显示异常文本?

问题描述:

我正在开发 Symfony,并按照 Symfony 文档的说明创建了一个自定义错误页面.

I'm working on Symfony and I created a custom error page, following the instruction of the Symfony documentation.

所以,我有我的应用程序/Ressources/TwigBundle/views/Exception/error.html.twig 文件.它工作正常,但在我的错误视图中,我想显示异常文本,以便如果我在控制器中执行此操作:

So, I have my app/Ressources/TwigBundle/views/Exception/error.html.twig file. It works fine, but in my error view, I want to display the Exception text, so that if I do this in a controller:

throw new \Exception('Ooops !');

...我可以显示值 'Ooops !'在我的树枝视图中.

...i can display the value 'Ooops !' in my Twig View.

有人知道哪个 Twig 变量有这个信息吗?

Do someone knows which Twig variable have this information ?

我终于找到了答案:异常消息可以通过 Twig 错误模板中的 exception.message 变量轻松访问.

I finally found the answer : the Exception Message is simply accessible by the exception.message variable in the Twig error template.