I would like to throw an exception from within the EVENT_DISPATCH
event that gets handled identical to how it would have been handled had it been thrown from a controllers dispatch method. However I have no clue how to do so.
In the first piece of code the exception is not caught and no EVENT_DISPATCH_ERROR is triggered. I tried to play with the MvcEvent::setError
method but no clue there.
$this->listeners[] = $events->attach(MvcEvent::EVENT_DISPATCH, array($this, 'onDispatch'), 100);
public function onDispatch(MvcEvent $e)
{
if ($condition) {
throw SomeException;
}
}
versus
class Controller extends AbstractActionController
{
public function onDispatch(MvcEvent $e)
{
if ($condition) {
throw SomeException;
}
}
}