displayTraceAction
This action is called if an exception is generated on a
non-production system, and will display a pretty stack trace.
@TODO Make stack trace pretty

@param \Exception $exception
@return Symfony\Component\HttpFoundation\Response $res;
162151
public function displayTraceAction(\Exception $exception)
    {
        $res = $this->getResponse();
        $res->setStatusCode(Response::HTTP_INTERNAL_SERVER_ERROR);
        $res->setContent(
            sprintf('Exception: %s<br>%s',
                $exception->getMessage(),
                nl2br($exception->getTraceAsString())
            )
        );

        return($res);

    }
819664
protected function format_exception( Exception $exception ) {
		$string = get_class( $exception );

		if ( ! empty( $exception->getMessage() ) ) {
			$string .= " : {$exception->getMessage()}";
		}

		if ( ! empty( $exception->getCode() ) ) {
			$string .= " (#{$exception->getCode()})";
		}

		return $string;
	}
168640
public function renderException(\Exception $exception)
    {
        $verbose = $this->console ? $this->console->get('verbose', 0) : 0;

        if (!$verbose) {
            $this->out()->err($exception->getMessage());

            return;
        }

        /** @var $exception \Exception */
        $class = get_class($exception);

        // @codingStandardsIgnoreStart
        $output = <<<EOF
<error>Exception '{$class}' with message:</error> <fg=cyan;options=bold>{$exception->getMessage()}</fg=cyan;options=bold>
<info>in {$exception->getFile()}:{$exception->getLine()}</info>

<error>Stack trace:</error>
{$exception->getTraceAsString()}
EOF;
        // @codingStandardsIgnoreEnd

        $this->out('');
        $this->err($output);
    }
733154
protected function _displayException($exception)
    {
        $errorName = 'Exception:';
        if ($exception instanceof FatalErrorException) {
            $errorName = 'Fatal Error:';
        }

        if ($exception instanceof PHP7ErrorException) {
            $exception = $exception->getError();
        }

        $message = sprintf(
            '<error>%s</error> %s in [%s, line %s]',
            $errorName,
            $exception->getMessage(),
            $exception->getFile(),
            $exception->getLine()
        );
        $this->_stderr->write($message);
    }
886013
protected function displayException($exception)
	{
		$displayer = $this->debug ? $this->debugDisplayer : $this->plainDisplayer;

		return $displayer->display($exception);
	}
221129
protected function getBacktrace(\Exception $exception)
    {
        $backtrace = array();

        $backtrace[] = '---';
        $backtrace[] = $this->getErrorMessage($exception);
        $backtrace[] = '---';

        // Allow marshalling of the trace: PHP marks getTraceAsString as final :-(
        if (method_exists($exception, 'getPreviousTraceAsString')) {
            $backtrace = array_merge($backtrace, explode("\n", $exception->getPreviousTraceAsString()));
        } else {
            $backtrace = array_merge($backtrace, explode("\n", $exception->getTraceAsString()));
        }

        if (($previous = $exception->getPrevious())) {
            $backtrace = array_merge($backtrace, $this->getBacktrace($previous)); // Recurse
        }

        return $backtrace;
    }
25937
protected function echoExceptionWeb($exception)
    {
        $statusCode = ($exception instanceof WithHttpStatusInterface) ? $exception->getStatusCode() : 500;
        $statusMessage = ResponseInformationHelper::getStatusMessageByCode($statusCode);
        if (!headers_sent()) {
            header(sprintf('HTTP/1.1 %s %s', $statusCode, $statusMessage));
        }

        if (!isset($this->renderingOptions['templatePathAndFilename'])) {
            $this->renderStatically($statusCode, $exception);
            return;
        }

        try {
            echo $this->buildView($exception, $this->renderingOptions)->render();
        } catch (\Throwable $throwable) {
            $this->renderStatically($statusCode, $throwable);
        }
    }
274000
public function render($request, Exception $exception)
    {
        if ($exception instanceof TokenExpiredException) {
            return response()->json(['token_expired'], $exception->getCode());
        } else if ($exception instanceof TokenInvalidException) {
            return response()->json(['token_invalid'], $exception->getCode());
        }
        return parent::render($request, $exception);
    }
698712
public function handle(Exception $exception): Response
    {
        foreach ($this->handlers as $hint => $handler) {
            if (!$exception instanceof $hint) {
                continue;
            }

            if ($response = $handler($exception)) {
                if (!$response instanceof BaseResponse) {
                    $response = new Response($response, $this->getExceptionStatusCode($exception));
                }

                return $response;
            }
        }

        return $this->genericResponse($exception);
    }
615633
private function eventMsg(\Exception $exception)
    {
        return sprintf('%s (%s line:%s)', $exception->getMessage(), $exception->getFile(), $exception->getLine());
    }
1074247
public function reportException(\Exception $exception)
    {
        $data = [

            // Request info.
            'method'    => $this->request->getMethod(),
            'ip'        => $this->request->getClientIps(),
            'path'      => $this->request->path(),
            'query'     => array_except($this->request->all(), ['_pjax', '_token', '_method', '_previous_']),
            'body'      => $this->request->getContent(),
            'cookies'   => $this->request->cookies->all(),
            'headers'   => array_except($this->request->headers->all(), 'cookie'),

            // Exception info.
            'exception' => get_class($exception),
            'code'      => $exception->getCode(),
            'file'      => $exception->getFile(),
            'line'      => $exception->getLine(),
            'message'   => $exception->getMessage(),
            'trace'     => $exception->getTraceAsString(),
        ];

        $data = $this->stringify($data);

        try {
            $this->store($data);
        } catch (\Exception $e) {
//            $result = $this->reportException($e);
        }

//        return $result;
    }
595868
protected function formatException(\Exception $exception)
    {
        if (!$this->pythonLike) {
            $s = (string) $exception;
            if (substr($s, -1) == "\n") {
                $s = substr($s, 0, -1);
            }
            return $s;
        }

        $s      = "Traceback (most recent call last):\n";
        $traces = array();
        foreach ($exception->getTrace() as $trace) {
            $origin = '';
            if (isset($trace['class'])) {
                $origin = $trace['class'].$trace['type'];
            }
            if (isset($trace['function'])) {
                $origin .= $trace['function'].'()';
            }
            if ($origin == '') {
                $origin = '???';
            }
            $file = isset($trace['file']) ? $trace['file'] : '{main}';
            $line = isset($trace['line']) ? $trace['line'] : 0;
            $traces[] = "File \"$file\", line $line, in $origin";
        }
        $s .= implode("\n", array_reverse($traces))."\n";
        $s .=   "Exception '" . get_class($exception) .
                "' with message '" . $exception->getMessage() .
                "' in " . $exception->getFile() .
                ":" . $exception->getLine();
        return $s;
    }
739919
protected function renderXmlErrorMessage(Exception $exception)
    {
        $xml = "<error>\n  <message>Slim Application Error</message>\n";
        if ($this->displayErrorDetails) {
            do {
                $xml .= "  <exception>\n";
                $xml .= "    <type>" . get_class($exception) . "</type>\n";
                $xml .= "    <code>" . $exception->getCode() . "</code>\n";
                $xml .= "    <message>" . $this->createCdataSection($exception->getMessage()) . "</message>\n";
                $xml .= "    <file>" . $exception->getFile() . "</file>\n";
                $xml .= "    <line>" . $exception->getLine() . "</line>\n";
                $xml .= "    <trace>" . $this->createCdataSection($exception->getTraceAsString()) . "</trace>\n";
                $xml .= "  </exception>\n";
            } while ($exception = $exception->getPrevious());
        }
        $xml .= "</error>";

        return $xml;
    }
68582
public function format(\Exception $exception)
    {
        $response = new Response();

        try {
            $response = $this->serialize(
                $this->config->isDebug() ? new Entity\DebugError($exception) : new Entity\Error($exception),
                is_null($this->request) ? Request::createFromGlobals() : $this->request,
                $response
            );
        } catch (\Exception $e) {
            $response->setContent(
                $this->serviceHateoas()->getSerializer()->serialize(
                    $this->config->isDebug() ? new Entity\DebugError($e) : new Entity\Error($e),
                    'json'
                )
            );

            $vendor = $this->getContainer()->get(Application::CONTAINER_ID_VENDOR);
            $apiVersion = $this->getContainer()->get(Application::CONTAINER_ID_API_VERSION);

            $response->headers->set('Content-Type', 'application/vnd.' . $vendor . '-v' . $apiVersion . '+json');
        }

        $response->setStatusCode(method_exists($exception, 'getStatusCode') ? $exception->getStatusCode() : 500);

        $response->sendHeaders();

        return $response->getContent();
    }
639434
static public function exceptionHandler($exception)
    {
        $msg = $exception->getMessage()
                . " Line "
                . $exception->getLine()
                . ", "
                . $exception->getFile();
        self::$logger->debug($msg);
    }
926449
protected function getStatusCode(Exception $exception): int
    {
        if ($exception instanceof ApiException) {
            return $exception->getStatusCode();
        }

        if ($exception instanceof HttpExceptionInterface && method_exists($exception, 'getStatusCode')) {
            return $exception->getStatusCode();
        }

        return 500;
    }
91268
public function trackException(Exception $exception)
    {
        $id = $this->trackIfEnabled('errors', function () use ($exception) {
            $this->getErrorTracker()->track($exception);
        });

        $this->mergeVisitorActivityData(['error_id' => $id]);
    }