Skip to content

Commit c74aa41

Browse files
committed
swap terminate and exception event descriptions
In #6631 we already fixed a sentence in the description. This change will also reflect the occurence of the events by the order in which their descriptions are shown.
1 parent 1e76648 commit c74aa41

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

components/console/events.rst

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,36 @@ C/C++ standard.::
8989
}
9090
});
9191

92+
The ``ConsoleEvents::EXCEPTION`` Event
93+
--------------------------------------
94+
95+
**Typical Purposes**: Handle exceptions thrown during the execution of a
96+
command.
97+
98+
Whenever an exception is thrown by a command, the ``ConsoleEvents::EXCEPTION``
99+
event is dispatched. A listener can wrap or change the exception or do
100+
anything useful before the exception is thrown by the application.
101+
102+
Listeners receive a
103+
:class:`Symfony\\Component\\Console\\Event\\ConsoleExceptionEvent` event::
104+
105+
use Symfony\Component\Console\Event\ConsoleExceptionEvent;
106+
use Symfony\Component\Console\ConsoleEvents;
107+
108+
$dispatcher->addListener(ConsoleEvents::EXCEPTION, function (ConsoleExceptionEvent $event) {
109+
$output = $event->getOutput();
110+
111+
$command = $event->getCommand();
112+
113+
$output->writeln(sprintf('Oops, exception thrown while running command <info>%s</info>', $command->getName()));
114+
115+
// get the current exit code (the exception code or the exit code set by a ConsoleEvents::TERMINATE event)
116+
$exitCode = $event->getExitCode();
117+
118+
// change the exception to another one
119+
$event->setException(new \LogicException('Caught exception', $exitCode, $event->getException()));
120+
});
121+
92122
The ``ConsoleEvents::TERMINATE`` Event
93123
--------------------------------------
94124

@@ -127,34 +157,4 @@ Listeners receive a
127157
It is then dispatched just after the ``ConsoleEvents::EXCEPTION`` event.
128158
The exit code received in this case is the exception code.
129159

130-
The ``ConsoleEvents::EXCEPTION`` Event
131-
--------------------------------------
132-
133-
**Typical Purposes**: Handle exceptions thrown during the execution of a
134-
command.
135-
136-
Whenever an exception is thrown by a command, the ``ConsoleEvents::EXCEPTION``
137-
event is dispatched. A listener can wrap or change the exception or do
138-
anything useful before the exception is thrown by the application.
139-
140-
Listeners receive a
141-
:class:`Symfony\\Component\\Console\\Event\\ConsoleExceptionEvent` event::
142-
143-
use Symfony\Component\Console\Event\ConsoleExceptionEvent;
144-
use Symfony\Component\Console\ConsoleEvents;
145-
146-
$dispatcher->addListener(ConsoleEvents::EXCEPTION, function (ConsoleExceptionEvent $event) {
147-
$output = $event->getOutput();
148-
149-
$command = $event->getCommand();
150-
151-
$output->writeln(sprintf('Oops, exception thrown while running command <info>%s</info>', $command->getName()));
152-
153-
// get the current exit code (the exception code or the exit code set by a ConsoleEvents::TERMINATE event)
154-
$exitCode = $event->getExitCode();
155-
156-
// change the exception to another one
157-
$event->setException(new \LogicException('Caught exception', $exitCode, $event->getException()));
158-
});
159-
160160
.. _`reserved exit codes`: http://www.tldp.org/LDP/abs/html/exitcodes.html

0 commit comments

Comments
 (0)