Quantcast
Channel: Symfony Blog
Viewing all articles
Browse latest Browse all 3056

New in Symfony 3.3: Better handling of command exceptions

$
0
0
Wouter De Jong

Contributed by
Wouter De Jong
in #18140.

The ConsoleEvents::EXCEPTION event is triggered as soon as an exception is thrown while running a console command. It's useful to change the exceptions or handle them in some way before the application throws them.

However, this event is only dispatched for exceptions during the execution ofCommand#execute(). All other exceptions (e.g. the ones thrown by listeners) are silently caught in the Application#doRunCommand() method. This means that there is no way to override exception handling in those cases.

In Symfony 3.3, we decided to improve the exception handling in commands with the introduction of a new ConsoleEvents::ERROR event and the deprecation of the ConsoleEvents::EXCEPTION event. A new ConsoleErrorEvent class has also been created and the ConsoleExceptionEvent class has been deprecated too.

In practice, the changes required in your application will be minimal. Just listen to the new ConsoleEvents::ERROR event and handle the exceptions as before, with the added possibility of handling more exceptions that may occur during the command execution.


Be trained by Symfony experts - 2017-04-03 Paris - 2017-04-04 London - 2017-04-04 London

Viewing all articles
Browse latest Browse all 3056

Trending Articles