Calls the exception methods.

@param ActionContext $actionContext The context of the action.
@param \Exception $exception The exception.

@return ExceptionContext
519512
private static function exceptionFilters($actionContext, $exception) {
        $context = new ExceptionContext($actionContext, $exception);
        
        $filters = $actionContext->getFilters();

        foreach ($filters as $filter) {
            $filter->exception($context);
        }

        return $context;
    }
913559
public function exceptionHandler($exception)
    {
        // Standard PHP Libraries Error
        if ($exception instanceof \Error) {
            $error = new ErrorException(
                $exception->getMessage(),
                $exception->getCode(),
                $exception->getFile(),
                $exception->getLine()
            );

            output()->write(
                (new Format())
                    ->setContextualClass(Format::DANGER)
                    ->setString(language()->getLine('E_CAUGHT_ERROR'))
                    ->setNewLinesAfter(1)
            );

            output()->write(
                (new Format())
                    ->setContextualClass(Format::WARNING)
                    ->setString('[ ' . language()->getLine($error->getStringSeverity()) . ' ] ' . $error->getMessage())
                    ->setNewLinesAfter(1)
            );

            output()->write(
                (new Format())
                    ->setContextualClass(Format::INFO)
                    ->setString($error->getFile() . ':' . $error->getLine())
                    ->setNewLinesAfter(1)
            );

            exit(EXIT_ERROR);
        } elseif ($exception instanceof AbstractException) {

            output()->write(
                (new Format())
                    ->setContextualClass(Format::DANGER)
                    ->setString(language()->getLine($exception->getHeader()))
                    ->setNewLinesAfter(1)
            );

            output()->write(
                (new Format())
                    ->setContextualClass(Format::DANGER)
                    ->setString('[ ' . language()->getLine($exception->getCode()) . ' ] ' . language()->getLine($exception->getDescription()))
                    ->setNewLinesAfter(1)
            );

            output()->write(
                (new Format())
                    ->setContextualClass(Format::DANGER)
                    ->setString($exception->getMessage())
                    ->setNewLinesAfter(1)
            );

            output()->write(
                (new Format())
                    ->setString($debugTitle = language()->getLine('E_DEBUG_BACKTRACE') . ':')
                    ->setContextualClass(Format::INFO)
                    ->setNewLinesBefore(1)
                    ->setNewLinesAfter(1)
            );

            output()->write((new Line(strlen($debugTitle) * 2))
                ->setContextualClass(Line::INFO)
                ->setNewLinesAfter(2));

            $table = new Table();
            $table->isShowBorder = false;

            $i = 1;
            foreach ($exception->getChronology() as $chronology) {
                $table
                    ->addRow()
                    ->addColumn($i . '. ' . $chronology->call)
                    ->addRow()
                    ->addColumn($chronology->file . ':' . $chronology->line)
                    ->addRow()
                    ->addColumn('');

                $i++;
            }

            output()->write(
                (new Format())
                    ->setContextualClass(Format::INFO)
                    ->setString($table->render())
                    ->setNewLinesAfter(2)
            );
        } // Standard PHP Libraries Exception
        elseif ($exception instanceof \Exception) {
            output()->write(
                (new Format())
                    ->setContextualClass(Format::DANGER)
                    ->setString('[ ' . language()->getLine($exception->getCode()) . ' ] ' . language()->getLine($exception->getMessage()))
                    ->setNewLinesAfter(1)
            );

            output()->write(
                (new Format())
                    ->setContextualClass(Format::DANGER)
                    ->setString($exception->getMessage())
                    ->setNewLinesAfter(1)
            );

            output()->write(
                (new Format())
                    ->setString($debugTitle = language()->getLine('E_DEBUG_BACKTRACE') . ':')
                    ->setContextualClass(Format::INFO)
                    ->setNewLinesBefore(1)
                    ->setNewLinesAfter(1)
            );

            output()->write((new Line(strlen($debugTitle) * 2))
                ->setContextualClass(Line::INFO)
                ->setNewLinesAfter(2));

            $table = new Table();
            $table->isShowBorder = false;

            $trace = new Trace($exception->getTrace());

            $i = 1;
            foreach ($trace->getChronology() as $chronology) {
                $table
                    ->addRow()
                    ->addColumn($i . '. ' . $chronology->call)
                    ->addRow()
                    ->addColumn($chronology->file . ':' . $chronology->line)
                    ->addRow()
                    ->addColumn('');

                $i++;
            }

            output()->write(
                (new Format())
                    ->setContextualClass(Format::INFO)
                    ->setString($table->render())
                    ->setNewLinesAfter(2)
            );
        }
    }
129805
protected function _actionException(AnCommandContext $context)
    {
        $viewer = $this->getService('com:people.viewer');

        if ($viewer->guest() && $context->data instanceof LibBaseControllerExceptionUnauthorized) {
            $this->getController()->setMessage('COM-PEOPLE-PLEASE-LOGIN-TO-SEE');
            $return = base64_encode(AnRequest::url());
            $context->response->setRedirect(route('option=com_people&view=session&return='.$return));
            $context->response->send();
            exit(0);

        } else {
            $this->getService('application.dispatcher')->execute('exception', $context);
        }
    }
1183002
protected void processContext(ActionContext actionContext) throws ServletException, IOException {
		Action action = null;
		try {
			// Find action binding
			ActionBinding actionBinding = findActionBinding(actionContext);
			// Create action
			if (actionBinding != null) {
				action = actionBinding.create(actionContext);
			}
			if (action == null) {
				throw new ActionException("No action bound to path " + actionContext.getPath());
			}
			// Read request parameters
			action.readParameters();
			// Execute action (generate response)
			action.execute();
		} catch (ActionException actionException) {
			// Handle action errors
			try {
				ErrorAction errorAction = new ErrorAction(actionContext);
				errorAction.setError(actionException);
				errorAction.execute();
			} catch (ActionException actionException1) {
				throw new ServletException(actionException);
			}
		}
	}
746237
private static function render($actionContext) {
        $controller = $actionContext->getController();

        // annotation and validation
        $modelState = $actionContext->getModelState();
        self::annotateAndValidateModel($modelState);

        // filters
        $actionExecutingContext = self::actionExecutingFilters($actionContext);

        if (($actionResult = $actionExecutingContext->getResult()) === null) {
            try {
                // execute action
                $actionResult = self::executeAction($actionContext);
                // filters
                $actionExecutedContext = self::actionExecutedFilters($actionContext, $actionResult);
                // set result
                $actionResult = $actionExecutedContext->getResult();
            }
            catch (\Exception $ex) {
                // set status code
                $actionContext->getHttpContext()->getResponse()->setStatusCode(500);
                // add the error to the modelState
                $modelState->addError('.', $ex);
                // filters
                $exceptionContext = self::exceptionFilters($actionContext, $ex);
                if (($actionResult = $exceptionContext->getResult()) === null) {
                    if ($exceptionContext->getExceptionHandled()) {
                        // executed filters
                        $actionExecutedContext = self::actionExecutedFilters($actionContext, $actionResult, $exceptionContext);
                        // set result
                        $actionResult = $actionExecutedContext->getResult();
                    }
                    else {
                        $actionResult = new ExceptionResult($ex);
                    }
                }
            }
        }

        if (isset($actionResult)) {
            // transformation of known types
            if (is_callable($actionResult)) {
                $actionResult = $actionResult();
            }

            if (is_scalar($actionResult)) {
                $actionResult = new ContentResult($actionResult, 'text/plain');
            }
            if ((($resultType = gettype($actionResult)) === 'object' || $resultType === 'array') && !$actionResult instanceof ActionResult) {
                $actionResult = new JsonResult($actionResult);
            }

            // make result
            if ($actionResult instanceof ViewResult || $actionResult instanceof ExceptionResult) {
                // create view data
                $viewData = $modelState->getKeyValuePair();
                $controllerViewData = InternalHelper::getPropertyValueOfParentClass($controller, 'viewData');

                if (!empty($controllerViewData)) {
                    $viewData = array_unique(array_merge($viewData, $controllerViewData), \SORT_STRING);
                }

                // create view
                $viewContext = InternalHelper::makeViewContext(
                    (!empty($actionResult->viewFile) ? $actionResult->viewFile : PHPMVC_CURRENT_VIEW_PATH),
                    $actionContext,
                    $actionResult,
                    null,
                    $viewData,
                    null,
                    null,
                    null
                );

                // get content
                $result = InternalHelper::getTopLevelViewContext($viewContext)->content;

                // render
                $response = $actionContext->getHttpContext()->getResponse();
                $response->write($result);
                $response->end();
            }
            elseif ($actionResult instanceof ActionResult) {
                // execute result with action context
                $actionResult->execute($actionContext);
            }
        }
    }
1182574
public function handleException(Exception $exception)
    {
        $severity = method_exists($exception, 'getSeverity') ? $exception->getSeverity() : self::ERROR_LEVEL;
        self::singleton()
            ->log(
                $severity,
                $exception->getMessage(),
                [
                    self::CONTEXT_EXCEPTION => get_class($exception),
                    self::CONTEXT_ERROR_FILE => $exception->getFile(),
                    self::CONTEXT_ERROR_LINE => $exception->getLine(),
                    self::CONTEXT_TRACE => $exception->getTrace()
                ]
            );
    }
1189793
public function handleException(ServerRequestInterface $request, ResponseInterface $response, Exception $exception)
    {
        return $this->withError($response, $exception);
    }
954802
private function handleException(\Exception $exception, Request $request, $type)
    {
        $event = new GetResponseForExceptionEvent($this, $request, $type, $exception);
        $this->application->getEventDispatcher()->dispatch(KernelEvents::EXCEPTION, $event);

        return $event->getResponse();
    }
337161
protected function createActionException(\Exception $e)
    {
        $this->handleException($e);

        return new RedirectResponse($this->admin->generateUrl('list'));
    }
1197877
public function stopAction(\Exception $exception = null)
    {
        $action = array_pop($this->actionStack);
        $this->lastActionIndex--;
        $action['time'] = microtime(true) - $action['time'] - $action['subtrahend'];
        if (null !== $exception) {
            $action['exception'] = $exception->getMessage();
        }
        unset($action['subtrahend']);
        $this->addSubtrahend($this->actionStack, $action['time']);
        $this->addSubtrahend($this->processorStack, $action['time']);
        $this->actions[] = $action;
        if (empty($this->actionStack) && $this->stopwatch) {
            $this->stopwatch->stop($this->getStopwatchName());
        }
    }
784080
public function handleException(\Exception $e)
	{
        $environment = $this->core->getCurrentDomain()->environment;
		
		if(isset($this->core->getSettings()->errorhandling->controller->$environment) === true) {
			$controller = FrameworkUtils::stringToClassName($this->core->getSettings()->errorhandling->controller->$environment);

			$pc = new $controller->className($this->core, $this->core->getHttpRequest(), new Route());

			$httpResponse = call_user_func(array($pc, $controller->methodName), $e);
		} else {
			$content = null;

			$httpErrorCode = ($e instanceof HttpException)?$e->getCode():500;
			$exceptionStr = null;

			if($this->core->getSettings()->core->environments->$environment->debug === true) {
				$exceptionStr = "\n<pre>";

				$exceptionStr .= '<b>Uncaught exception' . "\n" . '==================</b>' . "\n";
				$exceptionStr .= 'Type: ' . get_class($e) . "\n";
				$exceptionStr .= 'Message: ' . $e->getMessage() . ' (Code: ' . $e->getCode() . ')' . "\n";
				$exceptionStr .= 'Thrown in: ' . $e->getFile() . ' (Line: ' . $e->getLine() . ")\n\n";

				$exceptionStr .= $e->getTraceAsString();

				$exceptionStr .= '</pre>';
			}

			$errorStr = $httpErrorCode . ' ' . HttpResponse::getHttpStatusString($httpErrorCode);
			$content = "<!doctype html>\n<html>\n<head>\n<title>" . $errorStr . "</title>\n</head>\n<body>\n<h1>" . $errorStr . "</h1>" . $exceptionStr . "\n</body>\n</html>";

			$httpResponse = new HttpResponse($httpErrorCode, $content);
		}

		$httpResponse->send();

		exit;
	}
948505
protected function onInterruptionByException(ExtensionInterface $extension, Context $context)
    {
        $logger = $context->getLogger();

        $exception = $context->getException();
        $logger->error(
            sprintf('Consuming interrupted by exception. "%s"', $exception->getMessage()),
            ['exception' => $exception]
        );

        try {
            $extension->onInterrupted($context);
        } catch (\Exception $e) {
            // logic is similar to one in Symfony's ExceptionListener::onKernelException
            $logger->error(sprintf(
                'Exception thrown when handling an exception (%s: %s at %s line %s)',
                get_class($e),
                $e->getMessage(),
                $e->getFile(),
                $e->getLine()
            ));

            $wrapper = $e;
            while ($prev = $wrapper->getPrevious()) {
                if ($exception === $wrapper = $prev) {
                    throw $e;
                }
            }

            $prev = new \ReflectionProperty('Exception', 'previous');
            $prev->setAccessible(true);
            $prev->setValue($wrapper, $exception);

            throw $e;
        }

        throw $exception;
    }
602968
public function stopProcessor(\Exception $exception = null)
    {
        $processor = array_pop($this->processorStack);
        $processor['time'] = microtime(true) - $processor['time'] - $processor['subtrahend'];
        if (null !== $exception) {
            $processor['exception'] = $exception->getMessage();
        }
        unset($processor['subtrahend']);

        if (!empty($this->actionStack)) {
            if (!array_key_exists('processors', $this->actionStack[$this->lastActionIndex])) {
                $this->actionStack[$this->lastActionIndex]['processors'] = [$processor];
            } else {
                $this->actionStack[$this->lastActionIndex]['processors'][] = $processor;
            }
        } else {
            $this->unclassifiedProcessors[] = $processor;
        }
    }
129550
public static function generateFromException(Exception $exception, $action='Handling the request') {
		if( Config::get('forbidden_to_home', true) && $exception instanceof ForbiddenException ) {
			return new RedirectHTTPResponse(u(DEFAULTROUTE));
		}
		;
		$code = $exception->getCode();
		if( $code < 100 ) {
			$code = HTTP_INTERNAL_SERVER_ERROR;
		}
		$response = new static(convertExceptionAsHTMLPage($exception, $code, $action));
		$response->setCode($code);
		return $response;
	}
1218272
public function execute($actionContext) {
        $response = $actionContext->getHttpContext()->getResponse();
        $response->setStatusCode($this->statusCode);
        $response->setStatusDescription($this->statusDescription);
        $response->write($result);
        $response->end();
    }
254226
public function handleException(Exception &$exception)
    {
        if($template = end($this->_stack))
        {
            if($this->_source == $exception->getFile())
            {
                //Prevents any partial templates from leaking.
                ob_get_clean();

                //Re-create the exception and set the real file path
                if($exception instanceof ErrorException)
                {
                    $class = get_class($exception);
                    $file  = $this->getObject('template.locator.factory')->locate($template) ?: $this->_source;

                    $exception = new KTemplateExceptionError(
                        $exception->getMessage(),
                        $exception->getCode(),
                        $exception->getSeverity(),
                        $file,
                        $exception->getLine(),
                        $exception
                    );
                }
            }
        }
    }
858533
public static function fromException(\Exception $ex) {
    if ($ex instanceof ApplicationException) {
      return $ex->getError();
    }
    if ($ex instanceof AuthorizationException) {
      return self::get(PERMISSION_DENIED);
    }
    return self::getGeneral($ex->getMessage());
  }