static function render(\Throwable $exception, bool $renderTrace = true, bool $renderPrevious = false): string
    {
        $exceptions = $renderPrevious ? static::getChain($exception) : [$exception];
        $totalExceptions = count($exceptions);
        $lastException = $totalExceptions - 1;

        $output = '';
        for ($i = 0; $i < $totalExceptions; ++$i) {
            if ($i > 0 && $renderTrace) {
                $output .= "\n";
            }

            $output .= ($renderPrevious ? '[' . ($i + 1) . "/{$totalExceptions}] " : '')
                . static::getName($exceptions[$i])
                . ': ' . ($exceptions[$i]->getMessage() ?: '<no message>')
                . " in {$exceptions[$i]->getFile()} on line {$exceptions[$i]->getLine()}";

            if ($renderTrace || $i < $lastException) {
                $output .= "\n";
            }

            if ($renderTrace) {
                $output .= $exceptions[$i]->getTraceAsString();

                if ($i < $lastException) {
                    $output .= "\n";
                }
            }
        }

        return $output;
    }