function onUncaughtException(\Throwable $exception): void
    {
        try {
            // handle the exception
            try {
                $this->emit(ErrorHandlerEvents::EXCEPTION, $exception, $this->debug);
            } catch (\Throwable $e) {
                $exception = new ChainedException(
                    'Additional exception was thrown from an [exception] event listener. See previous exceptions.',
                    0,
                    Exception::joinChains($exception, $e)
                );
            }

            $this->invokeErrorScreen($exception);

            return;
        } catch (\Throwable $e) {
            $exception = new ChainedException(
                sprintf('Additional exception was thrown while trying to invoke %s. See previous exceptions.', get_class($this->errorScreen)),
                0,
                Exception::joinChains($exception, $e)
            );

            $this->emit(ErrorHandlerEvents::FAILURE, $exception, $this->debug);
        }

        // unhandled exception
        if ($this->debug && $this->printUnhandledExceptionInDebug) {
            echo Exception::render($exception, true, true);
        }
    }