The current PHP has been released to version 7.
I've been studying it for the last two days.
Now the new error handling and exception handling methods are not very clear how to use
I hope the great God can give an example
try { not_exists_func(); } catch (\EngineException $e) { echo $e->getMessage(); }
The above code does not throw an exception, what is it for?
Reply content:
The current PHP has been released to version 7.
I've been studying it for the last two days.
Now the new error handling and exception handling methods are not very clear how to use
I hope the great God can give an example
try { not_exists_func(); } catch (\EngineException $e) { echo $e->getMessage(); }
The above code does not throw an exception, what is it for?
PHP7 implements a global Throwable interface, the original exception and partial error both implement this interface (interface) and define the inheritance structure of the exception in the way of the interface. As a result, more error in PHP7 becomes a exception that can be captured and returned to the developer, error if not captured, and if the capture becomes a exception that can be processed within the program. These catch-all error is usually an error that does not cause fatal damage to the program, such as a function that does not exist.
\ What's this for?
Shouldn't you be new? What's this?
Try to remove it with a exception scratch
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);