function onShutdown(): void
    {
        // free the reserved memory
        $this->reservedMemory = null;

        if (
            $this->isActive()
            && ($error = error_get_last()) !== null
            && $error !== $this->lastError
        ) {
            $this->lastError = null;

            // fix working directory
            if ($this->workingDirectory !== null) {
                chdir($this->workingDirectory);
            }

            // determine exception class
            if ($this->isOutOfMemoryError($error)) {
                gc_collect_cycles();
                $exceptionClass = OutOfMemoryException::class;
            } else {
                $exceptionClass = FatalErrorException::class;
            }

            // handle
            $this->onUncaughtException(
                new $exceptionClass(
                    $error['message'],
                    0,
                    $error['type'],
                    $error['file'],
                    $error['line'],
                    $this->currentErrorException // use current error exception if a fatal error happens during onError()
                )
            );
        }
    }