From the Monolog library
@license MIT
@param  Exception $e
@return [type]       [description]
348722
protected function normalizeException(\Exception $e)
    {
        $data = array(
            'class' => get_class($e),
            'message' => $e->getMessage(),
            'code' => $e->getCode(),
            'file' => $e->getFile().':'.$e->getLine(),
        );

        $trace = $e->getTrace();
        foreach ($trace as $frame) {
            if (isset($frame['file'])) {
                $data['trace'][] = $frame['file'].':'.$frame['line'];
            } else {
                // We should again normalize the frames, because it might contain invalid items
                $data['trace'][] = $this->toJson($this->normalize($frame, array()), true);
            }
        }

        if ($previous = $e->getPrevious()) {
            $data['previous'] = $this->normalizeException($previous);
        }

        return $this->toJson($data);
    }
867985
protected function prepareException(Exception $e)
    {
        $e = parent::prepareException($e);

        if ($e instanceof MethodNotAllowedHttpException) {
            $e = new HttpException(405, 'Method not allowed', $e->getPrevious(), $e->getHeaders(), $e->getCode());
        }

        return $e;
    }
924168
public function writeException(\Exception $e)
    {
        if ($this->verboseException) {
            $text = sprintf("[%s]\n%s\nIn %s at line %s\n%s", 
                get_class($e),
                $e->getMessage(),
                $e->getFile(),
                $e->getLine(),
                $e->getTraceAsString()
            );
        } else {
            $text = sprintf("\n[%s]\n%s\n", get_class($e), $e->getMessage());
        }

        $box = new Widgets\Box($this->textWriter, $text, '');
        $out = Colors::colorizeLines($box, Colors::WHITE, Colors::RED);
        $out = TextFormater::apply($out, array('indent' => 2));
        $this->textWriter->writeln($out);
        return $this;
    }
1363689
public static function uncaughtExceptionHandler(\Exception $e)
    {
        if (Daemon::$context !== null) {
            if (Daemon::$context->handleException($e)) {
                return;
            }
        }
        $msg = $e->getMessage();
        Daemon::log('Uncaught ' . get_class($e) . ' (' . $e->getCode() . ')' . (mb_orig_strlen($msg) ? ': ' . $msg : '') . ".\n" . $e->getTraceAsString());
        if (Daemon::$context instanceof \PHPDaemon\Request\Generic) {
            Daemon::$context->out('<b>Uncaught ' . get_class($e) . ' (' . $e->getCode() . ')</b>' . (mb_orig_strlen($msg) ? ': ' . $msg : '') . '.<br />');
        }
    }
1027466
final public function reportException(\Exception $e)
	{
		$this->_addRow(
			array($e->getMessage()),
			$this->_formatLocation($e->getFile(), $e->getLine()),
			self::WARN
		);
	}
808489
protected function convertExceptionToResponse(Exception $e)
    {
        $e = FlattenException::create($e);
        $handler = new SymfonyExceptionHandler(DEBUG);
        echo $handler->getHtml($e);
    }
225836
public function formatException(\Exception $e) {
        $entry = array();

        $entry['class'] = get_class($e);
        $entry['message'] = $e->getMessage();
        $entry['file'] = $e->getFile();
        $entry['line'] = $e->getLine();
        $entry['trace'] = $e->getTraceAsString();

        return $entry;
    }
286824
public static function translate(\Exception $e): \Exception
    {
        if ($e instanceof \Doctrine\DBAL\Exception\ConnectionException) {
            return new \Caridea\Dao\Exception\Unreachable("System unreachable or connection timed out", $e->getCode(), $e);
        } elseif ($e instanceof \Doctrine\ORM\EntityNotFoundException ||
                $e instanceof \Doctrine\ORM\UnexpectedResultException ||
                $e instanceof \Doctrine\ODM\MongoDB\DocumentNotFoundException ||
                $e instanceof \Doctrine\ODM\CouchDB\DocumentNotFoundException) {
            return new \Caridea\Dao\Exception\Unretrievable("Data could not be retrieved", 404, $e);
        } elseif ($e instanceof \Doctrine\ORM\PessimisticLockException ||
                $e instanceof \Doctrine\ORM\OptimisticLockException ||
                $e instanceof \Doctrine\ODM\CouchDB\OptimisticLockException) {
            return new \Caridea\Dao\Exception\Conflicting("Optimistic or pessimistic concurrency failure", 409, $e);
        } elseif ($e instanceof \Doctrine\DBAL\Exception\UniqueConstraintViolationException) {
            return new \Caridea\Dao\Exception\Duplicative("Unique constraint violation", 409, $e);
        } elseif ($e instanceof \Doctrine\DBAL\Exception\ConstraintViolationException) {
            return new \Caridea\Dao\Exception\Violating("Constraint violation", 422, $e);
        } elseif ($e instanceof \Doctrine\ORM\Query\QueryException ||
                $e instanceof \Doctrine\ORM\Mapping\MappingException ||
                $e instanceof \Doctrine\DBAL\Exception\SyntaxErrorException ||
                $e instanceof \Doctrine\Common\Persistence\Mapping\MappingException) {
            return new \Caridea\Dao\Exception\Inoperable("Invalid API usage", 0, $e);
        }
        return new \Caridea\Dao\Exception\Generic("Uncategorized database error", 0, $e);
    }
37948
protected function renderExceptionContent(Exception $e)
    {
        try {
            return config('app.debug') && class_exists(Whoops::class)
                        ? $this->renderExceptionWithWhoops($e)
                        : $this->renderExceptionWithSymfony($e, config('app.debug'));
        } catch (Exception $e) {
            return $this->renderExceptionWithSymfony($e, config('app.debug'));
        }
    }
236692
public static function e2Array($e) {
        is_object($e) and $e = [
            'message' => $e->getMessage(),
            'file' => $e->getFile(),
            'line' => $e->getLine(),
            'trace' => $e->getTraceAsString(),
            'type' => $e->getCode()
        ];
        return $e;
    }
407601
public function exception($e)
    {
        $this->setParams(
            $e->getCode(),
            $e->getMessage(),
            $e->getFile(),
            $e->getLine(),
            $e->getTraceAsString());

        return $this->render();
    }
1300992
public function logDebugException(\Exception $e)
    {
        if ($this->getServerContext()->hasLogger(LoggerUtils::SYSTEM)) {
            $this->getServerContext()->getLogger(LoggerUtils::SYSTEM)->debug($e->__toString());
        }
    }
1169916
protected function processException(Exception $e)
    {
        $this->_lastRenderError = $e;

        if ($this->_errorListener) {
            call_user_func($this->_errorListener, $e, $this);
        }

        return '';
    }
885913
private function log(Exception $e)
    {
        $dontLog = [
//            AuthenticationException::class,
//            AuthorizationException::class,
            HttpException::class,
            StopException::class,
//            TokenMismatchException::class,
//            ValidationException::class,
        ];

        foreach ($dontLog as $type) {
            if ($e instanceof $type) {
                return;
            }
        }

        $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 QueryException) {
            $message = $data['message'] . '; sql: ' . $data['sql'];
        }
        else {
            $message = $data['message'];
        }

        logger()->error($class . ' in "' . $file . '", line ' . $line . ': ' . $message . ' (code ' . $code . ')');
    }
1305983
public function formatException(\Exception $ex)
    {
        return sprintf(
            $this->errorMessageFormat,
            $ex->getMessage(),
            $ex->getCode(),
            $ex->getFile(),
            $ex->getLine(),
            get_class($ex)
        );
    }
1047008
protected function error(\Exception $e)
    {
        $str  = sprintf("Message: %s\r\n", $e->getMessage());
        $str .= sprintf("Code: %s\r\n", $e->getCode());
        $str .= sprintf("File: %s (line: %s)\r\n", $e->getFile(), $e->getLine());
        $str .= sprintf("Trade: %s\r\n", $e->getTraceAsString());

        if ($this->log instanceof \Closure)
        {
            $log = $this->log;
            $log($str);
        }
    }
1179595
public static function ConvertToString (\Exception $e) {
		return sprintf(
			'#message %s %s(%s) %s',
			static::ConvertinternalEncoding($e->getMessage()),
			static::ConvertinternalEncoding($e->getFile()),
			$e->getLine(),
			static::ConvertinternalEncoding(str_replace(array("\n", "\r", "\r\n"), " ", $e->getTraceAsString()))
		);
	}