The current PHP version has been released to version 7. Two days ago, I have studied the new error handling and exception handling methods, but I don't quite understand how to use them. I hope you can give an example {code ...} the above Code cannot throw an exception. Why? PHP has been released to version 7.
I also studied it two days ago.
The new error handling and exception handling methods are not very clear about how to use them.
Hope you can give an example
try { not_exists_func(); } catch (\EngineException $e) { echo $e->getMessage(); }
The above Code cannot throw an exception. Why?
Reply content:
PHP has been released to version 7.
I also studied it two days ago.
The new error handling and exception handling methods are not very clear about how to use them.
Hope you can give an example
try { not_exists_func(); } catch (\EngineException $e) { echo $e->getMessage(); }
The above Code cannot throw an exception. Why?
PHP7 implements a global throwable interface. The original Exception and some errors both implement this interface and define the inheritance structure of exceptions in the form of interfaces. As a result, more errors in PHP 7 become caught exceptions and are returned to the developer. If no capture is performed, the Error is returned. If the capture is performed, the Exception can be processed in the program. These captured errors are usually errors that do not cause fatal damage to the program. For example, functions do not exist.
\ What is this?
Shouldn't it be new? Why?
Try to capture with Exception
getMessage());}output:string(44) "Call to undefined function not_exists_func()"
Open error report?
ini_set("display_errors", 1);error_reporting(E_ALL^E_NOTICE);