duannei1477 2018-04-05 10:37
浏览 168

这些水平线在PhpStorm IDE中代表什么?

They do not appear when I put the condition inside the try {}

enter image description here

  • 写回答

1条回答 默认 最新

  • doushuo8677 2018-04-05 12:36
    关注

    Phpstorm highlights those lines because one or more of the functions being called throws an Exception. There's three ways to go around this issue.

    Add a try / catch block

    you can surround the highlighted code with a try/ catch block, and then do something with the Exception (ex: logging the message to the console).

    public function get() {
        try {
            throw new Exception();
        }
        catch(Exception $e) {
            // do something
        }
    }
    

    Add a phpdoc comment to the function

    If you wish to let the potential Exception bubble up, you can simply add a phpdoc comment to your function. Be aware though, that unless you list every potential Exception, or the generic Exception type, Phpstorm will then warn you about missing @throws statement.

    /**
     * @throws Exception
     */
    public function get() {
        throw new Exception();
    }
    

    disable or alter the IDE settings

    The "Unhandled Exception" warning in Phpstorm is considered to be a warning, and not a syntax highlight. As such, you can either enable or disable it, or adjust its severity level. You can find the related setting in Settings > Editor > Inspections and then selecting PHP > Error handling > Unhandled expection

    I would advise against disabling the highlight, knowing when and where an Exception might thrown can help in preventing bugs and making the codebase generally more stable.


    Note that you can change the actual style of the warning, but doing so will affect any other warning of the same severity level. To do so, go in Settings > Editor > Color scheme > General > Errors and Warnings and select the warning level that applies (Warning by default)

    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向