public function throws($expected = null): CatchedException
    {
        $this->runCode();
        if (null === $this->exception) {
            throw new AssertionFailure(
                    'Failed asserting that '
                    . (null !== $expected
                        ? 'exception of type "' . (is_string($expected) ? $expected : get_class($expected)) . '"'
                        : 'an exception'
                    )
                    . ' is thrown.'
            );
        } elseif (null !== $expected) {
            if (is_string($expected)) {
                $isExpected = new ExpectedException($expected);
            } elseif ($expected instanceof \Throwable) {
                $isExpected = isSameAs($expected);
            } else {
                throw new \InvalidArgumentException(
                        'Given expected is neither a class name nor an instance'
                        . ' of \Throwable, but of type ' . gettype($expected)
                );
            }

            assertThat($this->exception, $isExpected);
        }

        return new CatchedException($this->exception);
    }