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.
\SodiumException
is from thesodium
extension.\PDOException
is from thepdo
extension.\RandomException
andRandomError
are from theRandom
extension 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\Error
or\Exception
classes.
Changes
PHP 8.0
\ValueError
is new in PHP 8.0.\UnhandledMatchError
is new in PHP 8.0.
PHP 8.1
\FiberError
and\FiberExit
are new in PHP 8.1.
PHP 8.2
\Random\RandomException
,\Random\RandomError
, and\Random\BrokenRandomEngineError
are from theRandom
extension added in PHP 8.2.
PHP 8.3
DateError
,DateObjectError
,DateRangeError
,DateException
,DateInvalidTimeZoneException
,DateInvalidOperationException
,DateMalformedStringException
,DateMalformedIntervalStringException
, andDateMalformedPeriodStringException
are added in PHP 8.3 as part of PHP 8.3: Granular DateTime Exceptions.SQLite3Exception
is from SQLite3: New\SQLite3Exception
, deprecations, and changes
PHP 8.4
\RequestParseBodyException
is new in PHP 8.4.