Skip to content

Commit

Permalink
swap terminate and exception event descriptions
Browse files Browse the repository at this point in the history
In symfony#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.
  • Loading branch information
xabbuh committed Jun 6, 2016
1 parent 1e76648 commit c74aa41
Showing 1 changed file with 30 additions and 30 deletions.
60 changes: 30 additions & 30 deletions components/console/events.rst
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,36 @@ C/C++ standard.::
}
});

The ``ConsoleEvents::EXCEPTION`` Event
--------------------------------------

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

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.

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

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

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

$command = $event->getCommand();

$output->writeln(sprintf('Oops, exception thrown while running command <info>%s</info>', $command->getName()));

// get the current exit code (the exception code or the exit code set by a ConsoleEvents::TERMINATE event)
$exitCode = $event->getExitCode();

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

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

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

The ``ConsoleEvents::EXCEPTION`` Event
--------------------------------------

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

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.

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

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

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

$command = $event->getCommand();

$output->writeln(sprintf('Oops, exception thrown while running command <info>%s</info>', $command->getName()));

// get the current exit code (the exception code or the exit code set by a ConsoleEvents::TERMINATE event)
$exitCode = $event->getExitCode();

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

.. _`reserved exit codes`: http://www.tldp.org/LDP/abs/html/exitcodes.html

0 comments on commit c74aa41

Please sign in to comment.