Hierarchy of PHP exceptions

Published On30 Mar 2020

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
        └── DateException
                ├── DateInvalidTimeZoneException
                ├── DateInvalidOperationException
                ├── DateMalformedStringException
                ├── DateMalformedIntervalStringException
                └── DateMalformedPeriodStringException

Notes

  • All of these exceptions are in the global namespace.
  • \SodiumException is from the sodium extension.
  • \PDOException is from the pdo extension.
  • \RandomException and RandomError are from the Random 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
PHP 8.1
PHP 8.2
PHP 8.3

Recent Articles on PHP.Watch

All ArticlesFeed 
How to Install/Upgrade PHP 8.3 on MacOS with Homebrew

How to Install/Upgrade PHP 8.3 on MacOS with Homebrew

Install PHP 8.3 and PHP extensions on MacOS with Homebrew.
How to install or upgrade to PHP 8.3 on Fedora, RHEL, CentOS, and more

How to install or upgrade to PHP 8.3 on Fedora, RHEL, CentOS, and more

Beginners guide on how to install PHP 8.3 on Fedora, RHEL, CentOS, Alma Linux, Rocky Linux, and others.
How to install or upgrade to PHP 8.3 on Ubuntu and Debian

How to install or upgrade to PHP 8.3 on Ubuntu and Debian

A complete guide to install or upgrade to PHP 8.3 on Ubuntu 22.04 (Jammy), Ubuntu 20.04 (Focal), Debian 10 (Buster), 11 (Bullseye), and Debian 12 (Bookworm).
Subscribe to PHP.Watch newsletter for monthly updates

You will receive an email on last Wednesday of every month and on major PHP releases with new articles related to PHP, upcoming changes, new features and what's changing in the language. No marketing emails, no selling of your contacts, no click-tracking, and one-click instant unsubscribe from any email you receive.