function onError(int $code, string $message, ?string $file = null, ?int $line = null): bool
    {
        $this->lastError = error_get_last();
        $this->currentErrorException = new ErrorException(
            $message,
            $code,
            ($code & error_reporting()) === 0,
            $file ?? __FILE__,
            $line ?? __LINE__
        );

        try {
            try {
                $this->emit(ErrorHandlerEvents::ERROR, $this->currentErrorException, $this->debug);
            } catch (\Throwable $e) {
                throw new ChainedException(
                    'Additional exception was thrown from an [error] event listener. See previous exceptions.',
                    0,
                    Exception::joinChains($this->currentErrorException, $e)
                );
            }

            // check suppression state
            if (!$this->currentErrorException->isSuppressed()) {
                throw $this->currentErrorException;
            }

            // suppressed error
            return true;
        } finally {
            $this->currentErrorException = null;
        }
    }