List of all exceptions in PHP available out of the box
List of all Throwable classes available out of the box in PHP:
Throwable - Parent interface for all throw objects. ├── Error - Base class for errors. │ ├── ArithmeticError - Error occurring during mathematical operations. │ │ └── DivisionByZeroError - Division by zero error. │ ├── AssertionError - Error caused by an unexecuted assertion check. │ ├── CompileError - Compilation error. │ ├── ParseError - Error occurring during parsing of PHP code. │ ├── TypeError - Type error when the argument or return value of a function does not match the declared type. │ └── ValueError - Value error when a function receives an argument of the correct type but incorrect value. └── Exception - Base class for all exceptions. ├── ErrorException - Error accompanied by an error message. ├── ClosedGeneratorException - Thrown when trying to resume a generator that has already finished. ├── LogicException - Thrown when an error is detected during program execution. │ ├── BadFunctionCallException - Thrown when a function cannot be called. │ ├── BadMethodCallException - Thrown when a class method cannot be called. │ ├── DomainException - Thrown when domain rules are violated. │ ├── InvalidArgumentException - Thrown when a function argument is invalid. │ ├── LengthException - Thrown when the length of a parameter is invalid. │ └── OutOfRangeException - Thrown when trying to use a value that is outside the allowed range. ├── PharException - Special PHP exception thrown when working with phar archives. ├── RangeException - Thrown when a value is not within the established range. ├── ReflectionException - Thrown when a reflection error occurs. ├── RuntimeException - Base class for exceptions that occur during program execution. │ ├── OutOfBoundsException - Thrown when trying to access an invalid index. │ ├── OverflowException - Thrown when an overflow occurs. │ ├── UnderflowException - Thrown on underflow, i.e., when a value is too small. │ └── UnexpectedValueException - Thrown when an unexpected value is received. └── SodiumException - Exceptions thrown by the Sodium library.
The same list in table format:
| Exception | Description |
|---|---|
| ArgumentCountError | Error caused by an incorrect int of arguments when calling a function. |
| ArithmeticError | Error occurring during mathematical operations. |
| AssertionError | Error caused by an unexecuted assertion check. |
| BadFunctionCallException | Thrown when a function cannot be called. |
| BadMethodCallException | Thrown when a class method cannot be called. |
| ClosedGeneratorException | Thrown when trying to resume a generator that has already finished. |
| CompileError | Occurs on compilation error. |
| DivisionByZeroError | Division by zero error. |
| DomainException | Thrown when domain rules are violated. |
| Error | Base class for all errors. |
| ErrorException | Error accompanied by an error message. |
| Exception | Base class for all exceptions. |
| InvalidArgumentException | Thrown when a function argument is invalid. |
| LengthException | Thrown when the length of a parameter is invalid. |
| LogicException | Thrown when an error is detected during program execution. |
| OutOfBoundsException | Thrown when trying to access an invalid index. |
| OutOfRangeException | Thrown when trying to use a value that is outside the allowed range. |
| OverflowException | Thrown when an overflow occurs. |
| ParseError | Error occurring during parsing of PHP code. |
| PharException | Special PHP exception thrown when working with phar archives. |
| RangeException | Thrown when a value is not within the established range. |
| ReflectionException | Thrown when a reflection error occurs. |
| RuntimeException | Base class for exceptions that occur during program execution. |
| SodiumException | Exceptions thrown by the Sodium library. |
| TypeError | Thrown when a function argument or return value does not match the declared type. |
| UnderflowException | Thrown on underflow, i.e., when a value is too small. |
| UnexpectedValueException | Thrown when an unexpected value is received. |
| ValueError | Thrown when a function receives an argument of the correct type but incorrect value. |
| Throwable | Parent interface for all objects that throw exceptions using throw. |
Named exceptions are used in PHP for more precise error handling. They allow for handling specific errors, as well as creating more readable and maintainable code, giving the developer more information about the error beyond just the error text.
Using more specific types of exceptions helps to more accurately identify and handle errors.