Helper method that writes critical system exceptions to the system
logger if configured.

@param \Exception $e The exception to be logged

@return void
960404
public function logCriticalException(\Exception $e)
    {
        if ($this->getServerContext()->hasLogger(LoggerUtils::SYSTEM)) {
            $this->getServerContext()->getLogger(LoggerUtils::SYSTEM)->critical($e->__toString());
        }
    }
1321105
public function handleException($e)
    {
        if (!$e instanceof Exception) {
            $e = new FatalThrowableError($e);
        }

        $this->getExceptionRenderer()->render($e, $this->debug());
    }
454183
public function appException($e)
    {
        throw new ErrorException($e->getCode(), $e->getMessage(), $e->getFile(), $e->getLine(), $e->getTrace());

    }
1090346
public function handle($e)
	{
		$this->logException($e);

		if ($this->isExceptionHalting($e))
		{
			if (ob_get_contents() !== false) ob_end_flush();
			if($this->_showStackTrace) echo "\n".$e->__toString()."\n\n";
			exit(self::EXIT_CODE);
		}
	}
551385
public function logServerError(Throwable $e)
    {
        if ($this->isInTesting()) {
            return;
        }

        $exception = $this->normalizeException($e);
        $this->container->make(ConsoleOutput::class)
            ->writeln(sprintf("<error>%s</error>", $exception));

        $this->container->make(ExceptionHandler::class)
            ->report($exception);
    }
988748
public static function writeException($e)
    {
        if ($e instanceof \Exception) {
            $text = sprintf("%s\n[%s]\n%s", $e->getFile() . ':' . $e->getLine(), get_class($e), $e->getMessage());
        } else {
            $text = $e;
        }

        $box = new Box($text, '*');
        $out = Colour::colour($box, [Colour::WHITE, 0], Colour::RED);
        $format = new Format(['indent' => 2]);
        $out = $format->format($out);
        self::writeln($out, STDERR);
    }
652184
public function report(Exception $e)
    {
        try {
            $logger = Zilf::$container->getShare('log');
        } catch (Exception $ex) {
            throw $e;
        }

        $logger->error($e->getMessage(), ['exception' => $e]);
    }
66078
protected function showErrorAndDie(\Exception $e)
    {
        $this->error('And error occurs connecting to the api url: ' . $this->url);
        if ($e->getResponse()) {
            $this->error('Status code: ' . $e->getResponse()->getStatusCode() . ' | Reason : ' . $e->getResponse()->getReasonPhrase());
        } else {
            $this->error('Exception occurs. Message: ' . $e->getMessage());
        }

        die();
    }
1245937
protected function catchException(\Exception $e)
    {
        foreach ($this->onException as $call) {
            call_user_func_array($call, [$e]);
        }

        throw $e;
    }
1276555
public function logErrorException(\Exception $e)
    {
        if ($this->getServerContext()->hasLogger(LoggerUtils::SYSTEM)) {
            $this->getServerContext()->getLogger(LoggerUtils::SYSTEM)->error($e->__toString());
        }
    }
164245
public function setExceptionMessages(Exception $e)
    {
        $this->flashMessenger()->addErrorMessage([
            'message' => $e->getMessage(),
            'title' => 'Error!'
        ]);

        $prevException = $e->getPrevious();

        if ($prevException) {
            while ($prevException) {
                $this->flashMessenger()->addErrorMessage($prevException->getMessage());
                $prevException = $prevException->getPrevious();
            }
        }
    }
64344
public function writeException(Exception $e)
    {
        $class = get_class($e);
        $text = $this->adapter->colorize("Exception - $class:\n{$e->getMessage()}\n", ColorInterface::LIGHT_RED);

        if ($this->isVerbose()) {
            $text .= "\n" . $this->renderTrace($e->getTrace()) . "\n";

            if ($this->isVeryVerbose() && ($previous = $e->getPrevious())) {
                $text .= "\n" . $this->adapter->colorize('Previous Exceptions:', ColorInterface::YELLOW) . "\n\n";

                do {
                    $class = $this->adapter->colorize(get_class($previous), ColorInterface::YELLOW);
                    $msg = $this->adapter->colorize($previous->getMessage(), ColorInterface::GRAY);
                    $text .= sprintf('%s: %s', $class, $msg)
                           . "\n" . $this->renderTrace($e->getTrace()) . "\n\n";
                } while ($previous = $previous->getPrevious());
            }
        }

        $this->adapter->writeLine($text);
    }
416964
protected function _logException(Exception $exception) {
		if ($this->is404($exception)) {
			$level = LOG_ERR;
			Log::write($level, $this->_getMessage($exception), ['404']);
			return false;
		}
		return parent::_logException($exception);
	}
1285722
public function PHPExceptionHandler($exception)
    {
        session_write_close();
        $message = $exception->getMessage() . ' | File: {file} | Ln: {line} | ST: {stacktrace}';
        $context = array(
            'file' => $exception->getFile(),
            'line' => $exception->getLine(),
            'stacktrace' => $exception->getTraceAsString()
        );
        $this->logger->log($this->exceptionLogLevel, $message, $context);
    }
740280
protected function addError(Exception $e) {
        $errors = $this->getErrors();
        $errors[] = $e;
        $this->setErrors($errors);
    }
1056920
private function handleForConsole(Exception $e)
    {
        if ($e instanceof StopException) {
            $output = $e->getMessage();
        }
        else {
            $data = $this->convertException($e);
            $class = get_class($e);
            $file  = $this->stripFile($data['file']);
            $line  = $data['line'];
            $code  = $data['code'];

            // set the error message
            if ($e instanceof HttpException) {
                $message = http_status_text($data['status']) . ' (' . $data['status'] . ')';
                if (!empty($data['message'])) {
                    $message .=  '. ' . $data['message'];
                }
            }
            else if ($e instanceof QueryException) {
                $message = $data['message'] . '; sql: ' . $data['sql'];
            }
            else {
                $message = $data['message'];
            }

            $output = $class . ' in "' . $file . '", line ' . $line . ':' . PHP_EOL . $message . ' (code ' . $code . ')';
        }

        stdio()->error($output);

        $exitCode = $e->getCode();
        if ($exitCode === null) {
            $exitCode = Command::EXIT_FAILURE;
        }

        exit ($exitCode);
    }
1016063
public function handleException(\Throwable $e) : void
    {
        $this->report($e);
        if ($this->getConfigParam('env') != 'prod') {
            throw $e;
        }
        $response = $this->throwableToResponse($e);
        $this->responseSender->sendResponse($response);
    }