in minitest/ExpectObj.hack [86:119]
public function toThrow<TEx as \Throwable>(
classname<TEx> $ex,
?string $ex_message = null,
?string $_failure_message = null,
): TEx where T = (function(): mixed) {
$thrown = null;
try {
$f = $this->value;
$ret = $f();
if ($ret is Awaitable<_>) {
\HH\Asio\join($ret);
}
} catch (\Throwable $t) {
$thrown = $t;
}
$thrown = expect($thrown)->toNotBeNull();
self::assert(
\is_a($thrown, $ex),
$_failure_message ??
'Expected to throw "'.$ex."\", but instead got:\n".$thrown->__toString()
);
if ($ex_message is nonnull) {
self::assert(
\strpos($thrown?->getMessage() ?? '', $ex_message) !== false,
$_failure_message ??
'Expected the exception message to be "'.
$ex_message.
"\", but instead got:\n".
$thrown->__toString()
);
}
/* HH_FIXME[4110] verified with is_a() */
return $thrown;
}