Encodera

Thanks for reading!

Donate to the site — we work hard for you.

PHP reference

Error

The base class of PHP's internal errors.

Syntax

catch (Error $e) { … }

Return value

ErrorAn object with the same methods as `Exception`.

Examples

Calling a function that does not exist:

<?php
 
try {
    no_such_function();
} catch (Error $e) {
    echo $e->getMessage();
}

Output:

Call to undefined function no_such_function()

Notes

Subclasses: TypeError, ValueError, ArithmeticError, DivisionByZeroError, ArgumentCountError. Such errors usually mean a bug in the code that should be fixed rather than worked around.

See also

  • Throwable — The common interface of everything that can be thrown and caught.
  • TypeError — The error of a mismatched argument or return type.
  • Exception — The base class of exceptions.

In the tutorial

  • Exceptions — Exceptions in PHP — throw, try, catch and finally, custom exception classes and built-in errors.

Thanks for reading!

Donate to the site — we work hard for you.