I'm working on Symfony and I created a custom error page, following the instruction of the Symfony documentation.
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 !');
...i can display the value 'Ooops !' in my Twig View.
Do someone knows which Twig variable have this information ?
And when they do, we show our users an error page. Hopefully, a hilarious error page. Right now, our 404 page isn’t very hilarous, except for the little Pacman ghost that’s screaming “Exception detected”. He’s adorable. We see this big descriptive error page because we’re in the dev environment, and Symfony wants to help us fix our mistake.
Behind the scenes, Symfony dispatches an event whenever an exception happens. We haven’t talked about events yet, but this basically means that if you want, you can be nofitied whenever an exception is thrown anywhere in your code.
When an exception is thrown by an ASP.NET page and is not handled, the exception percolates up to the ASP.NET runtime, which displays the configured error page.
In PHPStorm, I can navigate to vendor/symfony/symfony, right click, then select “Find in Path”. Let’s look for the “An Error Occurred” text.
I finally found the answer : the Exception Message is simply accessible by the exception.message variable in the Twig error template.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With