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

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
PHP 8.4

Recent Articles on PHP.Watch

All ArticlesFeed 
How to fix `mysql_native_password` not loaded errors on MySQL 8.4

How to fix mysql_native_password not loaded errors on MySQL 8.4

How to fix the SQLSTATE[HY000] [1524] Plugin 'mysql_native_password' is not loaded errors caused in MySQL 8.4 no longer enabling the mysql_native_password plugin by default.
How to fix PHP Curl HTTPS Certificate Authority issues on Windows

How to fix PHP Curl HTTPS Certificate Authority issues on Windows

On Windows, HTTPS requests made with the Curl extension can fail because Curl has no root certificate list to validate the server certificates. This article discusses the secure and effective solutions, and highlights bad advice that can leave PHP applications insecure.
AEGIS Encryption with PHP Sodium Extension

AEGIS Encryption with PHP Sodium Extension

The Sodium extension in PHP 8.4 now supports AEGIS-128L and AEGIS256 Authenticated Encryption ciphers. They are significantly faster than AES-GCM and CHACHA20-POLY1305. This article benchmarks them and explains how to securely encrypt and decrypt data using AEGIS-128L and AEGIS256 on PHP.
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.

Support PHP.Watch — If you find the articles, version information, Codex, and other PHP.Watch contributions useful, consider supporting through GitHub Sponsors. Your sponsorship helps dedicate more time to creating valuable content and improving the PHP community. Together, we can keep the momentum going — thank you for your support!

Thanks to the highest tier sponsor: @TomasVotruba for your generous support to keep PHP.Watch moving 💜