function ThrowPromise::__construct
Initializes promise.
@phpstan-param class-string<\Throwable>|\Throwable $exception
Parameters
string|\Throwable $exception Exception class name or instance:
Throws
\Prophecy\Exception\InvalidArgumentException
File
-
vendor/
phpspec/ prophecy/ src/ Prophecy/ Promise/ ThrowPromise.php, line 43
Class
- ThrowPromise
- Throws predefined exception.
Namespace
Prophecy\PromiseCode
public function __construct($exception) {
if (is_string($exception)) {
if (!class_exists($exception) && !interface_exists($exception) || !$this->isAValidThrowable($exception)) {
throw new InvalidArgumentException(sprintf('Exception / Throwable class or instance expected as argument to ThrowPromise, but got %s.', $exception));
}
}
elseif (!$exception instanceof \Exception && !$exception instanceof \Throwable) {
throw new InvalidArgumentException(sprintf('Exception / Throwable class or instance expected as argument to ThrowPromise, but got %s.', is_object($exception) ? get_class($exception) : gettype($exception)));
}
$this->exception = $exception;
}