dongshang6062 2019-01-23 03:20
浏览 114

如何在使用try catch时隐藏PHP错误

I am doubt of PHP's try catch mechanism about why when l using try catch to process the error, but PHP still show the default error message

For example, l'm using PHP excel lib to parse the xls file, but l wanna to print a user friendly error output, like

{code:1, msg:"some error"}

So l do these:

    try {
        return $this->getJSON($fileName);
    }catch (Exception $e){
        $f = fopen('/' . trim(ROOT_DIR, '/\\') . '/file/Excel_error', 'wb');
        fwrite($f, $e);
        $split_content = "

-------------------------------------

";
        fwrite($f, $split_content);
        fclose($f);
        echo json_encode(array(
            "code" => 10000,
            "msg" => "Excel parse error",
            "files"=>null
        ));
    }

l want to log the error file and output my custom msg to front-end, but it doesn't work, When l trigger a error/warning or others, PHP still show the PHP Error/E_WARINING ... like follow screenshot

enter image description here

PS: l process the file in getJSON(), this function is my entrance.

  • 写回答

1条回答 默认 最新

  • dqbjvg2518 2019-01-23 03:32
    关注

    You can change the error handling and logging section in the php.ini file. You could change the value of the error_reporting to E_ERROR to reduce the verbosity of the reporting and to avoid the warnings to be displayed.

    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记