/** * @param ActionEvent $actionEvent * @param \Exception $ex * @throws Exception\MessageDispatchException */ protected function handleException(ActionEvent $actionEvent, \Exception $ex) { $failedPhase = $actionEvent->getName(); $actionEvent->setParam(self::EVENT_PARAM_EXCEPTION, $ex); $this->triggerError($actionEvent); $this->triggerFinalize($actionEvent); //Check if a listener has removed the exception to indicate that it was able to handle it if ($ex = $actionEvent->getParam(self::EVENT_PARAM_EXCEPTION)) { $actionEvent->setName($failedPhase); throw MessageDispatchException::failed($actionEvent, $ex); } }
/** * @param ActionEvent $actionEvent * @param \Exception $previousException * @return MessageDispatchException */ public static function failed(ActionEvent $actionEvent, \Exception $previousException = null) { $ex = new self(sprintf("Message dispatch failed during %s phase.%s", $actionEvent->getName(), is_null($previousException) ? '' : ' Error: ' . $previousException->getMessage()), 422, $previousException); $ex->setFailedDispatch($actionEvent); return $ex; }