New in Symfony 4.1: Exception improvements

FlattenException now unwraps errors

Contributed by
Alexander M. Turek
in #26028.

Symfony wraps errors thrown by the application inside a FatalThrowableError. This makes the actual error class to not be displayed in the exception pages, where you see for example Symfony's FatalThrowableError instead of PHP's DivisionByZeroError when your code tries to divide by 0.

In Symfony 4.1, FlattenException now unwraps FatalThrowableError instances and logs the wrapped error. In consequence, the real error class is now always displayed in the exception page:

Introduced new exception classes

Contributed by
Sullivan Senechal and Florent Mata
in #25775 and #26475.

In Symfony 4.1 we've introduced a new ProcessSignaledException class in the Process component to properly catch signaled process errors. Also, in the HttpFoundation component, we've introduced new detailed exception classes for file upload handling to replace the generic catch-all FileException:

1
2
3
4
5
6
7
use Symfony\Component\HttpFoundation\File\Exception\CannotWriteFileException;
use Symfony\Component\HttpFoundation\File\Exception\ExtensionFileException;
use Symfony\Component\HttpFoundation\File\Exception\FormSizeFileException;
use Symfony\Component\HttpFoundation\File\Exception\IniSizeFileException;
use Symfony\Component\HttpFoundation\File\Exception\NoFileException;
use Symfony\Component\HttpFoundation\File\Exception\NoTmpDirFileException;
use Symfony\Component\HttpFoundation\File\Exception\PartialFileException;

Moreover, now that PHP 7.1 supports multi catch exception handling, you can process several exceptions with the same catch() block:

1
2
3
4
5
try {
    // ...
} catch (FormSizeFileException | IniSizeFileException $e) {
    // ...
}

Improved the exception page design

Contributed by
Javier Eguiluz
in #26671.

The exception pages have been improved in Symfony 4.1 to display less information about "vendor code". If some code belongs to the vendor/ folder, we compact its information to fit in a single line and we no longer display its arguments. The other code remains the same, which helps you focus more easily on your own application code:

Comments

Awesome! Thanks!
This will make troubleshooting a lot easier, thanks!
Love those tiny bits and pieces that tend to make developemt and debugging (especially) painless :-) Thanks folks!
Thanks for continuously improving the Developer Experience :)
Awesome improvements, that's gonna be a real game changer when it comes to debugging and error solving.
This looks great - thanks to the contributors.
Thanks, that's nice !
Great ! it's easier to read.
It is such a pleasure to develop and learn daily with Symfony - thanks for your hard work and contributions. :)
Great! Thank you!

Comments are closed.

To ensure that comments stay relevant, they are closed for old posts.