@@ -97,13 +97,24 @@ Whenever an exception is thrown by a command, the ``ConsoleEvents::EXCEPTION``
97
97
event is dispatched. A listener can wrap or change the exception or do
98
98
anything useful before the exception is thrown by the application.
99
99
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
+
100
111
Listeners receive a
101
- :class: `Symfony\\ Component\\ Console\\ Event\\ ConsoleExceptionEvent ` event::
112
+ :class: `Symfony\\ Component\\ Console\\ Event\\ ConsoleErrorEvent ` event::
102
113
103
- use Symfony\Component\Console\Event\ConsoleExceptionEvent ;
114
+ use Symfony\Component\Console\Event\ConsoleErrorEvent ;
104
115
use Symfony\Component\Console\ConsoleEvents;
105
116
106
- $dispatcher->addListener(ConsoleEvents::EXCEPTION , function (ConsoleExceptionEvent $event) {
117
+ $dispatcher->addListener(ConsoleEvents::ERROR , function (ConsoleErrorEvent $event) {
107
118
$output = $event->getOutput();
108
119
109
120
$command = $event->getCommand();
@@ -114,22 +125,9 @@ Listeners receive a
114
125
$exitCode = $event->getExitCode();
115
126
116
127
// 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 ()));
118
129
});
119
130
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
-
133
131
The ``ConsoleEvents::TERMINATE `` Event
134
132
--------------------------------------
135
133
0 commit comments