Hierarchy of PHP exceptions

Published On2020-03-30

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
  └── Exception
        ├── ClosedGeneratorException
        ├── DOMException
        ├── ErrorException
        ├── IntlException
        ├── JsonException
        ├── LogicException
        │       ├── BadFunctionCallException
        │       │        └── BadMethodCallException
        │       ├── DomainException
        │       ├── InvalidArgumentException
        │       ├── LengthException
        │       └── OutOfRangeException
        ├── PharException
        ├── ReflectionException
        ├── RuntimeException
        │       ├── OutOfBoundsException
        │       ├── OverflowException
        │       ├── PDOException
        │       ├── RangeException
        │       ├── UnderflowException
        │       ├── UnexpectedValueException
        │       └── PDOException
        └── SodiumException
  • \ValueError is new in PHP 8.0.
  • \UnhandledMatchError is new in PHP 8.0.
  • All of these exceptions are in the global namespace.
  • \SodiumException is from the sodium extension.
  • \PDOException is from the pdo extension.
  • 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.

Recent Articles on PHP.Watch

All ArticlesFeed
PHP 8.0 Reached Feature-Freeze

PHP 8.0 Reached Feature-Freeze

PHP 8.0 reached its feature-freeze, which means we know which major features make it to PHP 8.0.
How to use Union Types in PHP

How to use Union Types in PHP

A practical guide to when and how to use Union Types introduced in PHP 8.0
PHP 8: Override internal functions with `disable_functions` INI directive

PHP 8: Override internal functions with `disable_functions` INI directive

Creative ways to polyfill/mock PHP internal functions with `disabled_functions` feature
Subscribe to PHP.Watch newsletter for monthly updates

You will receive an email on last Saturday 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.