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);
    }
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);
    }
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 ) ; }
asserts the code throws an exception when executed

If no expected is given any thrown exception will be sufficient.

@api
@param   string|\Throwable  $expected  optional  type of exception or the exact exception
@return  \bovigo\assert\CatchedException
@throws  \bovigo\assert\AssertionFailure
@throws  \InvalidArgumentException
asserts the code throws an exception when executed