Exception Handling Mechanism in php


In the java programming language, there is a relatively perfect exception handling mechanism, and the inside has been encapsulated relatively well. However, the exception handling mechanism in php is not so powerful and perfect. How is it implemented and does it treat every exception as an error?

PHP has a built-in base class Exception. You need to inherit this class to define your own exception.
When an exception is triggered, it is captured by the catch keyword to handle the exception.

catch (MyException $e) {
 //MyException process here  ...

Throwing exceptions can do this:

$myException = new MyException(/*something here*/);
 throw $myException;