0

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 = "\n\n-------------------------------------\n\n";
        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.

afraid.jpg
  • 965
  • 2
  • 14
  • 31
  • 1
    Possible duplicate of [PHP: exceptions vs errors?](https://stackoverflow.com/questions/841500/php-exceptions-vs-errors) – Nick Jan 23 '19 at 03:30

1 Answers1

0

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.

Byron Rodríguez
  • 191
  • 2
  • 10