Skip to content

Commit 980dd85

Browse files
committed
minor #10725 Change setException to setError (Landerstraeten)
This PR was merged into the 3.4 branch. Discussion ---------- Change setException to setError #SymfonyConHackDay2018 Commits ------- d9a5c2a Fix console error event
2 parents 239136d + d9a5c2a commit 980dd85

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

components/console/events.rst

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,24 @@ Whenever an exception is thrown by a command, the ``ConsoleEvents::EXCEPTION``
9797
event is dispatched. A listener can wrap or change the exception or do
9898
anything useful before the exception is thrown by the application.
9999

100+
The ``ConsoleEvents::ERROR`` Event
101+
----------------------------------
102+
103+
**Typical Purposes**: Handle exceptions thrown during the execution of a
104+
command.
105+
106+
Whenever an exception is thrown by a command, including those triggered from
107+
event listeners, the ``ConsoleEvents::ERROR`` event is dispatched. A listener
108+
can wrap or change the exception or do anything useful before the exception is
109+
thrown by the application.
110+
100111
Listeners receive a
101-
:class:`Symfony\\Component\\Console\\Event\\ConsoleExceptionEvent` event::
112+
:class:`Symfony\\Component\\Console\\Event\\ConsoleErrorEvent` event::
102113

103-
use Symfony\Component\Console\Event\ConsoleExceptionEvent;
114+
use Symfony\Component\Console\Event\ConsoleErrorEvent;
104115
use Symfony\Component\Console\ConsoleEvents;
105116

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

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

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

120-
The ``ConsoleEvents::ERROR`` Event
121-
----------------------------------
122-
123-
.. versionadded:: 3.3
124-
The ``ConsoleEvents::ERROR`` event was introduced in Symfony 3.3.
125-
126-
**Typical Purposes**: Handle exceptions thrown during the execution of a
127-
command.
128-
129-
This event is an improved version of the ``ConsoleEvents::EXCEPTION`` event,
130-
because it can handle every exception thrown during the execution of a command,
131-
including those triggered from event listeners.
132-
133131
The ``ConsoleEvents::TERMINATE`` Event
134132
--------------------------------------
135133

0 commit comments

Comments
 (0)