public function triggers(int $expectedError = null): CatchedError
    {
        if (null !== $expectedError && !CatchedError::knowsLevel($expectedError)) {
            throw new \InvalidArgumentException('Unknown error level ' . $expectedError);
        }

        set_error_handler(
                function(int $errno , string $errstr, string $errfile, int $errline, array $errcontext): bool
                {
                    $this->error = new CatchedError($errno, $errstr, $errfile, $errline, $errcontext);
                    return true;
                }
        );
        $this->runCode();
        restore_error_handler();
        if (null === $this->error) {
            throw new AssertionFailure(
                    'Failed asserting that '
                    . (null !== $expectedError
                        ? 'error of type "' . CatchedError::nameOf($expectedError) . '"'
                        : 'an error'
                    )
                    . ' is triggered.'
            );
        } elseif (null !== $expectedError) {
            assertThat($this->error, new ExpectedError($expectedError));
        }

        return $this->error;
    }