Explain the Exception Hierarchy introduced in PHP7

Technology CommunityCategory: PHPExplain the Exception Hierarchy introduced in PHP7
VietMX Staff asked 3 years ago

Prior to PHP 7 alpha-2, the exception hierarchy in PHP 7 was different. Fatal and recoverable errors threw instances of EngineException, which did not inherit from Exception. Both Exception and EngineException inherited from BaseException.

To unite the two exception branches, Exception and Error both implement a new interface, Throwable. So the new hierarchy is:

 |- Exception implements Throwable
       |- …
    |- Error implements Throwable
        |- TypeError extends Error
        |- ParseError extends Error
        |- ArithmeticError extends Error
            |- DivisionByZeroError extends ArithmeticError
        |- AssertionError extends Error