PhpStorm 在注释 @throws 标记中无法识别我的自定义异常

PhpStorm not recognize my custom exception in comment @throws tag

我在构造中有一个自定义异常,但 PhpStorm 2018.2 无法识别 class 并说:

PHPDoc comment doesn't contain all necessary @throws tag(s)

use App\Domain\Common\Exception\InvalidUUIDException;
....
/**
 * @param null|string $id
 * @throws InvalidUUIDException
 */
public function __construct(string $id = null)
{
    try {

        $this->uuid = Uuid::fromString($id ?: Uuid::uuid4())->toString();

    } catch (\InvalidArgumentException $e) {

        throw new InvalidUUIDException();
    }
}

我可以想到三个备选方案:

  1. 注释缺失的异常:

    /**
     * @param null|string $id
     * @throws InvalidUUIDException if `$id` is not a valid UUID
     * @throws \Exception if new UUID generation failed
     */
    
  2. 捕获丢失的异常:

    try {
        $this->uuid = Uuid::fromString($id ?: Uuid::uuid4())->toString();
    } catch (\InvalidArgumentException $e) {
        throw new InvalidUUIDException();
    } catch (\Exception $e) {
        // Do something interesting here
    }
    

    或(这里不合适,因为两个异常都有不同的原因):

    try {
        $this->uuid = Uuid::fromString($id ?: Uuid::uuid4())->toString();
    } catch (\InvalidArgumentException | \Exception $e) {
        throw new InvalidUUIDException();
    }
    
  3. 直接忽略检查

我认为这几乎涵盖了所有内容;-)