Hierarchy of PHP exceptions
PHP is on its way to use more and more exceptions, and with PHP 8.0 throwing \TypeError and \ValueError exceptions, you will be seeing lots of exceptions working with modern PHP!
Here is a quick chart to help you take an overview look at the Exceptions used in PHP versions:
Throwable
├── Error
│ ├── ArithmeticError
│ │ └── DivisionByZeroError
│ ├── AssertionError
│ ├── CompileError
│ │ └── ParseError
│ ├── TypeError
│ │ └── ArgumentCountError
│ ├── ValueError
│ ├── UnhandledMatchError
| ├── FiberError
| └── Random\RandomError
│ │ └── BrokenRandomEngineError
| └── DateError
| ├── DateObjectError
│ └── DateRangeError
└── Exception
├── ClosedGeneratorException
├── DOMException
├── ErrorException
├── IntlException
├── JsonException
├── LogicException
│ ├── BadFunctionCallException
│ │ └── BadMethodCallException
│ ├── DomainException
│ ├── InvalidArgumentException
│ ├── LengthException
│ └── OutOfRangeException
├── PharException
├── ReflectionException
├── RuntimeException
│ ├── OutOfBoundsException
│ ├── OverflowException
│ ├── RangeException
│ ├── UnderflowException
│ ├── UnexpectedValueException
│ └── PDOException
├── SodiumException
├── FiberExit
├── Random\RandomException
├── SQLite3Exception
├── DateException
│ ├── DateInvalidTimeZoneException
│ ├── DateInvalidOperationException
│ ├── DateMalformedStringException
│ ├── DateMalformedIntervalStringException
│ └── DateMalformedPeriodStringException
└── RequestParseBodyException
Notes
- All of these exceptions are in the global namespace.
\SodiumExceptionis from thesodiumextension.\PDOExceptionis from thepdoextension.\RandomExceptionandRandomErrorare from theRandomextension added in PHP 8.2.- The list is not exhaustive. Additional extensions might add more exceptions, but you can catch them all by catching
\Throwable, or by the more specific\Erroror\Exceptionclasses.
Changes
PHP 8.0
\ValueErroris new in PHP 8.0.\UnhandledMatchErroris new in PHP 8.0.
PHP 8.1
\FiberErrorand\FiberExitare new in PHP 8.1.
PHP 8.2
\Random\RandomException,\Random\RandomError, and\Random\BrokenRandomEngineErrorare from theRandomextension added in PHP 8.2.
PHP 8.3
DateError,DateObjectError,DateRangeError,DateException,DateInvalidTimeZoneException,DateInvalidOperationException,DateMalformedStringException,DateMalformedIntervalStringException, andDateMalformedPeriodStringExceptionare added in PHP 8.3 as part of PHP 8.3: Granular DateTime Exceptions.SQLite3Exceptionis from SQLite3: New\SQLite3Exception, deprecations, and changes
PHP 8.4
\RequestParseBodyExceptionis new in PHP 8.4.


