Skip to content

Change setException to setError #10725

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 27, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 15 additions & 17 deletions components/console/events.rst
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,24 @@ Whenever an exception is thrown by a command, the ``ConsoleEvents::EXCEPTION``
event is dispatched. A listener can wrap or change the exception or do
anything useful before the exception is thrown by the application.

The ``ConsoleEvents::ERROR`` Event
----------------------------------

**Typical Purposes**: Handle exceptions thrown during the execution of a
command.

Whenever an exception is thrown by a command, including those triggered from
event listeners, the ``ConsoleEvents::ERROR`` event is dispatched. A listener
can wrap or change the exception or do anything useful before the exception is
thrown by the application.

Listeners receive a
:class:`Symfony\\Component\\Console\\Event\\ConsoleExceptionEvent` event::
:class:`Symfony\\Component\\Console\\Event\\ConsoleErrorEvent` event::

use Symfony\Component\Console\Event\ConsoleExceptionEvent;
use Symfony\Component\Console\Event\ConsoleErrorEvent;
use Symfony\Component\Console\ConsoleEvents;

$dispatcher->addListener(ConsoleEvents::EXCEPTION, function (ConsoleExceptionEvent $event) {
$dispatcher->addListener(ConsoleEvents::ERROR, function (ConsoleErrorEvent $event) {
$output = $event->getOutput();

$command = $event->getCommand();
Expand All @@ -114,22 +125,9 @@ Listeners receive a
$exitCode = $event->getExitCode();

// changes the exception to another one
$event->setException(new \LogicException('Caught exception', $exitCode, $event->getException()));
$event->setError(new \LogicException('Caught exception', $exitCode, $event->getError()));
});

The ``ConsoleEvents::ERROR`` Event
----------------------------------

.. versionadded:: 3.3
The ``ConsoleEvents::ERROR`` event was introduced in Symfony 3.3.

**Typical Purposes**: Handle exceptions thrown during the execution of a
command.

This event is an improved version of the ``ConsoleEvents::EXCEPTION`` event,
because it can handle every exception thrown during the execution of a command,
including those triggered from event listeners.

The ``ConsoleEvents::TERMINATE`` Event
--------------------------------------

Expand Down