Skip to content

Instantly share code, notes, and snippets.

@TravisCarden
Last active April 10, 2023 12:35
Show Gist options
  • Save TravisCarden/f6b712c6d3a0b7d3b9a8cb48781710f9 to your computer and use it in GitHub Desktop.
Save TravisCarden/f6b712c6d3a0b7d3b9a8cb48781710f9 to your computer and use it in GitHub Desktop.
List of all PHP exceptions

All PHP exceptions up to PHP 8.1

All, with Hierarchy

  • Exception (PHP 5, PHP 7, PHP 8) is the base class for all user exceptions.
    • ErrorException (PHP 5 >= 5.1.0, PHP 7, PHP 8) is an Error Exception.
    • LogicException (PHP 5 >= 5.1.0, PHP 7, PHP 8) represents an error in the program logic. This kind of exception should lead directly to a fix in your code.
      • BadFunctionCallException (PHP 5 >= 5.1.0, PHP 7, PHP 8) is thrown if a callback refers to an undefined function or if some arguments are missing.
        • BadMethodCallException (PHP 5 >= 5.1.0, PHP 7, PHP 8) is thrown if a callback refers to an undefined method or if some arguments are missing.
      • DomainException (PHP 5 >= 5.1.0, PHP 7, PHP 8) is thrown if a value does not adhere to a defined valid data domain.
      • InvalidArgumentException (PHP 5 >= 5.1.0, PHP 7, PHP 8) is thrown if an argument is not of the expected type.
      • LengthException (PHP 5 >= 5.1.0, PHP 7, PHP 8) is thrown if a length is invalid.
      • OutOfRangeException (PHP 5 >= 5.1.0, PHP 7, PHP 8) is thrown when an illegal index was requested. This represents errors that should be detected at compile time.
    • RuntimeException (PHP 5 >= 5.1.0, PHP 7, PHP 8) is thrown if an error which can only be found on runtime occurs.
      • OutOfBoundsException (PHP 5 >= 5.1.0, PHP 7, PHP 8) is thrown if a value is not a valid key. This represents errors that cannot be detected at compile time.
      • OverflowException (PHP 5 >= 5.1.0, PHP 7, PHP 8) is thrown when adding an element to a full container.
      • RangeException (PHP 5 >= 5.1.0, PHP 7, PHP 8) is thrown to indicate range errors during program execution. Normally this means there was an arithmetic error other than under/overflow. This is the runtime version of DomainException.
      • UnderflowException (PHP 5 >= 5.1.0, PHP 7, PHP 8) is thrown when performing an invalid operation on an empty container, such as removing an element.
      • UnexpectedValueException (PHP 5 >= 5.1.0, PHP 7, PHP 8) is thrown if a value does not match with a set of values. Typically this happens when a function calls another function and expects the return value to be of a certain type or value not including arithmetic or buffer related errors.
  • Error (PHP 7, PHP 8) is the base class for all internal PHP errors.
    • ArithmeticError (PHP 7, PHP 8) is thrown when an error occurs while performing mathematical operations. These errors include attempting to perform a bitshift by a negative amount, and any call to intdiv() that would result in a value outside the possible bounds of an int.
      • DivisionByZeroError (PHP 7, PHP 8) is thrown when an attempt is made to divide a number by zero.
    • AssertionError (PHP 7, PHP 8) is thrown when an assertion made via assert() fails.
    • CompileError (PHP 7 > 7.3.0, PHP 8) is thrown for some compilation errors, which formerly issued a fatal error.
      • ParseError (PHP 7, PHP 8) is thrown when an error occurs while parsing PHP code, such as when eval() is called.
    • FiberError (PHP 8 >= 8.1.0) is thrown when an invalid operation is performed on a Fiber.
    • TypeError (PHP 7, PHP 8) may be thrown when: 1) The value being set for a class property does not match the property's corresponding declared type. 2) The argument type being passed to a function does not match its corresponding declared * parameter type. 3) A value being returned from a function does not match the declared function return type.
      • ArgumentCountError (PHP 7 >= PHP 7.1.0, PHP 8) is thrown when too few arguments are passed to a user-defined function or method.
    • UnhandledMatchError (PHP 8) is thrown when the subject passed to a match expression is not handled by any arm of the match expression.
    • ValueError (PHP 8) is thrown when the type of an argument is correct but the value of it is incorrect. For example, passing a negative integer when the function expects a positive one, or passing an empty string/array when the function expects it to not be empty.
Exception PHP 5 PHP 7 PHP 8 Description
Exception 5 7 8 The base class for all user exceptions.
ErrorException >= 5.1.0 7 8 An Error Exception.
Error 7 8 The base class for all internal PHP errors.
ArgumentCountError >= 7.1.0 8 Thrown when too few arguments are passed to a user-defined function or method.
ArithmeticError 7 8 Thrown when an error occurs while performing mathematical operations. These errors include attempting to perform a bitshift by a negative amount, and any call to intdiv() that would result in a value outside the possible bounds of an int.
AssertionError 7 8 Thrown when an assertion made via assert() fails.
DivisionByZeroError 7 8 Thrown when an attempt is made to divide a number by zero.
CompileError > 7.3.0 8 Thrown for some compilation errors, which formerly issued a fatal error.
ParseError 7 8 Thrown when an error occurs while parsing PHPcode, such as when eval() is called.
TypeError 7 8 May be thrown when: 1) The value being set for a class property does not match the property's corresponding declared type. 2) The argument type being passed to a function does not match its corresponding declared * parameter type. 3) A value being returned from a function does not match the declared function return type.
ValueError 8 Thrown when the type of an argument is correct but the value of it is incorrect. For example, passing a negative integer when the function expects a positive one, or passing an empty string/array when the function expects it to not be empty.
UnhandledMatchError 8 Thrown when the subject passed to a match expression is not handled by any arm of the match expression.
Exception 5 7 8 Description
FiberError >= 8.1.0 Thrown when an invalid operation is performed on a Fiber.
BadFunctionCallException >= 5.1.0 7 8 Thrown if a callback refers to an undefined function or if some arguments are missing.
BadMethodCallException >= 5.1.0 7 8 Thrown if a callback refers to an undefined method or if some arguments are missing.
DomainException >= 5.1.0 7 8 Thrown if a value does not adhere to a defined valid data domain.
InvalidArgumentException >= 5.1.0 7 8 Thrown if an argument is not of the expected type.
LengthException >= 5.1.0 7 8 Thrown if a length is invalid.
LogicException >= 5.1.0 7 8 Represents an error in the program logic. This kind of exception should lead directly to a fix in your code.
OutOfBoundsException >= 5.1.0 7 8 Thrown if a value is not a valid key. This represents errors that cannot be detected at compile time.
OutOfRangeException >= 5.1.0 7 8 Thrown when an illegal index was requested. This represents errors that should be detected at compile time.
OverflowException >= 5.1.0 7 8 Thrown when adding an element to a full container.
RangeException >= 5.1.0 7 8 Thrown to indicate range errors during program execution. Normally this means there was an arithmetic error other than under/overflow. This The runtime version of DomainException.
RuntimeException >= 5.1.0 7 8 Thrown if an error which can only be found on runtime occurs.
UnderflowException >= 5.1.0 7 8 Thrown when performing an invalid operation on an empty container, such as removing an element.
UnexpectedValueException >= 5.1.0 7 8 Thrown if a value does not match with a set of values. Typically this happens when a function calls another function and expects the return value to be of a certain type or value not including arithmetic or buffer related errors.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment