PhpStorm: what to do with unhandled exceptions when preconditions are met

What helps for me is to set @throws to Null

Example:

    /**
     * @return SomeObject
     * @throws Null
     *
     */

From phpStorm version 2018.1 you can exclude any exceptions from analysis. Go to preferences->Languages & Frameworks->PHP and open Analysis tab.

enter image description here

Here you can add exceptions to Unchecked Exceptions list


@noinspection tag can be used to instruct PhpStorm to suppress an inspection. The tag can be used above the line, above the method or on top of the file after <?php word:

/** @noinspection PhpDocMissingThrowsInspection */
/**
 *
 * Cancels order.
 *
 * @return bool
 */
public static function cancel()
{
    if (!self::inProgress()) return false;
    /** @noinspection PhpUnhandledExceptionInspection*/
    static::current()->delete();
    return true;
}

List of inspections can be found in this gist: https://gist.github.com/discordier/ed4b9cba14652e7212f5


You can also disable it via interface. ALT+ENTER then right arrow and Suppress ...


The correct way is add @throws tag into documentation (PhpStorm manual). For example:

    /**
     * @param $userId
     * @return array|null
     * @throws \Exception   <---------------------------
     */
    public static function send($userId)
    {
        if (empty($userId)) {
            throw new \Exception("User ID is missing", 1);
        }
        // ...
    }

Tags:

Php

Phpstorm