PhpStorm无法识别comment@throws标记中的自定义异常
我在构造中有一个自定义异常,但PhpStorm 2018.2无法识别类并说: PHPDoc注释未包含所有必需的@throws标记PhpStorm无法识别comment@throws标记中的自定义异常,phpstorm,Phpstorm,我在构造中有一个自定义异常,但PhpStorm 2018.2无法识别类并说: PHPDoc注释未包含所有必需的@throws标记 我可以想出三种选择: 注释缺少的异常: /** * @param null|string $id * @throws InvalidUUIDException if `$id` is not a valid UUID * @throws \Exception if new UUID generation failed */ try { $this-&
我可以想出三种选择:
/**
* @param null|string $id
* @throws InvalidUUIDException if `$id` is not a valid UUID
* @throws \Exception if new UUID generation failed
*/
try {
$this->uuid = Uuid::fromString($id ?: Uuid::uuid4())->toString();
} catch (\InvalidArgumentException $e) {
throw new InvalidUUIDException();
} catch (\Exception $e) {
// Do something interesting here
}
/**
* @param null|string $id
* @throws InvalidUUIDException if `$id` is not a valid UUID
* @throws \Exception if new UUID generation failed
*/
try {
$this->uuid = Uuid::fromString($id ?: Uuid::uuid4())->toString();
} catch (\InvalidArgumentException $e) {
throw new InvalidUUIDException();
} catch (\Exception $e) {
// Do something interesting here
}
或(此处不适用,因为两种例外情况的原因不同):
我认为这几乎涵盖了一切;-) 所以。。。缺少哪些异常(对应于PhpStorm)?如果您选择“修复”类操作,它将添加哪些例外情况?显示屏幕截图(以便我们尽可能提供更多建议)Google搜索的Uuid::fromString,已找到,因此如果您使用的是该屏幕截图,您可能需要捕获
\Ramsey\Uuid\Exception\InvalidUuidStringException
。不过,随机猜测是可行的,否则,懒骨头说的。杰托的发现在我看来是正确的——这和我的想法是一样的。同时,\Uuid\Exception\InvalidUuidStringException
是\InvalidArgumentException
的子类,因此应该包含它。。。您只需要查看IDE对它的看法,然后才能确定IDE是否仍然正确,或者它是否是一个明显的错误。Uuid::uuid4()
can抛出\Exception。这就是IDE理解缺少此异常的原因。如果我通过catch(\Exception$e)
修改方法并更改catch行,问题就解决了,但是调用它的方法无法识别它抛出异常,IDE也不会警告我应该处理它。