function Assert::throws
@psalm-param class-string<Throwable> $class
Parameters
Closure $expression:
string $class:
string $message:
Throws
File
-
vendor/
webmozart/ assert/ src/ Assert.php, line 1936
Class
- Assert
- Efficient assertions to validate the input/output of your methods.
Namespace
Webmozart\AssertCode
public static function throws(Closure $expression, $class = 'Exception', $message = '') {
static::string($class);
$actual = 'none';
try {
$expression();
} catch (Exception $e) {
$actual = \get_class($e);
if ($e instanceof $class) {
return;
}
} catch (Throwable $e) {
$actual = \get_class($e);
if ($e instanceof $class) {
return;
}
}
static::reportInvalidArgument($message ?: \sprintf('Expected to throw "%s", got "%s"', $class, $actual));
}