src/Stub/StubData.php
public function throws(...$exceptions): Stub
    {
        if (empty($exceptions)) {
            return $this->doesWith(
                function () {
                    throw new Exception();
                },
                [],
                false,
                false,
                false
            );
        }

        foreach ($exceptions as $exception) {
            if (is_string($exception)) {
                $exception = new Exception($exception);
            } elseif ($exception instanceof InstanceHandle) {
                $exception = $exception->get();
            }

            $this->doesWith(
                function () use ($exception) {
                    throw $exception;
                },
                [],
                false,
                false,
                false
            );
        }

        return $this;
    }
public function throws(...$exceptions): Stub
    {
        if (empty($exceptions)) {
            return $this->doesWith(
                function () {
                    throw new Exception();
                },
                [],
                false,
                false,
                false
            );
        }

        foreach ($exceptions as $exception) {
            if (is_string($exception)) {
                $exception = new Exception($exception);
            } elseif ($exception instanceof InstanceHandle) {
                $exception = $exception->get();
            }

            $this->doesWith(
                function () use ($exception) {
                    throw $exception;
                },
                [],
                false,
                false,
                false
            );
        }

        return $this;
    }
public function throws ( ... $ exceptions ) : Stub { if ( empty ( $ exceptions ) ) { return $ this -> doesWith ( function ( ) { throw new Exception ( ) ; } , [ ] , false , false , false ) ; } foreach ( $ exceptions as $ exception ) { if ( is_string ( $ exception ) ) { $ exception = new Exception ( $ exception ) ; } elseif ( $ exception instanceof InstanceHandle ) { $ exception = $ exception -> get ( ) ; } $ this -> doesWith ( function ( ) use ( $ exception ) { throw $ exception ; } , [ ] , false , false , false ) ; } return $ this ; }
Add an answer that throws an exception.

Calling this method with no arguments is equivalent to calling it with a
single argument of `null`.

@param Throwable|string|null ...$exceptions The exceptions, or messages, or nulls to throw generic exceptions.

@return $this This stub.
Add an answer that throws an exception .