Blog de programación, errores, soluciones

Chose Language:
comments
Author: Admin/Publisher |not checked

PHP – Predefined Exceptions

PHP provides a robust mechanism for handling errors and exceptions through its built-in exception classes. These exceptions are organized in a hierarchical structure, making it easier to catch and handle specific types of errors.

Predefined Exceptions Class Tree

  • Error (Implements Throwable)
    • ArithmeticError
      • DivisionByZeroError
    • AssertionError
    • CompileError
      • ParseError
    • TypeError
      • ArgumentCountError
    • ValueError
    • UnhandledMatchError
    • FiberError
  • Exception (Implements Throwable)
    • ErrorException

Exception: Exception is the base class for all exceptions in PHP 5 and for all user exceptions in PHP 7.

Since PHP 7, Exception implements the Throwable interface.

Description / Descripción
Exception implements Throwable {
/* Properties */
protected string $message ;
protected int $code ;
protected string $file ;
protected int $line ;
/* Methods */
public __construct ([ string $message = "" [, int $code = 0 [, Throwable $previous = NULL ]]] )
final public getMessage ( void ) : string
final public getPrevious ( void ) : Throwable
final public getCode ( void ) : mixed
final public getFile ( void ) : string
final public getLine ( void ) : int
final public getTrace ( void ) : array
final public getTraceAsString ( void ) : string
public __toString ( void ) : string
final private __clone ( void ) : void
}

ErrorException: error exceptions

Description / Descripción
ErrorException extends Exception {
/* Properties */
protected int $severity ;
/* Inherited properties */
protected string $message ;
protected int $code ;
protected string $file ;
protected int $line ;
/* Methods */
public __construct ([ string $message = "" [, int $code = 0 [, int $severity = E_ERROR [, string $filename = __FILE__ [, int $lineno = __LINE__ [, Exception $previous = NULL ]]]]]] )
final public getSeverity ( void ) : int
/* Inherited methods */
final public Exception::getMessage ( void ) : string
final public Exception::getPrevious ( void ) : Throwable
final public Exception::getCode ( void ) : mixed
final public Exception::getFile ( void ) : string
final public Exception::getLine ( void ) : int
final public Exception::getTrace ( void ) : array
final public Exception::getTraceAsString ( void ) : string
public Exception::__toString ( void ) : string
final private Exception::__clone ( void ) : void
}

Error : is the basic class for error exceptions(PHP7)

Description / Descripción
Error implements Throwable {
/* Properties */
protected string $message ;
protected int $code ;
protected string $file ;
protected int $line ;
/* Methods */
public __construct ([ string $message = "" [, int $code = 0 [, Throwable $previous = NULL ]]] )
final public getMessage ( void ) : string
final public getPrevious ( void ) : Throwable
final public getCode ( void ) : mixed
final public getFile ( void ) : string
final public getLine ( void ) : int
final public getTrace ( void ) : array
final public getTraceAsString ( void ) : string
public __toString ( void ) : string
final private __clone ( void ) : void
}

ArgumentCountError: This exception is thrown when too few arguments are passed to a function or method. (Available since PHP 7.1.0)

Description / Descripción
ArgumentCountError extends TypeError {
/* Inherited properties */
protected string $message ;
protected int $code ;
protected string $file ;
protected int $line ;
/* Inherited methods */
final public Error::getMessage ( void ) : string
final public Error::getPrevious ( void ) : Throwable
final public Error::getCode ( void ) : mixed
final public Error::getFile ( void ) : string
final public Error::getLine ( void ) : int
final public Error::getTrace ( void ) : array
final public Error::getTraceAsString ( void ) : string
public Error::__toString ( void ) : string
final private Error::__clone ( void ) : void
}

ArithmeticError: It is thrown when an error occurs during mathematical operations.

Description / Descripción
ArithmeticError extends Error {
/* Métodos heredados */
final public Error::getMessage ( void ) : string
final public Error::getPrevious ( void ) : Throwable
final public Error::getCode ( void ) : mixed
final public Error::getFile ( void ) : string
final public Error::getLine ( void ) : int
final public Error::getTrace ( void ) : array
final public Error::getTraceAsString ( void ) : string
public Error::__toString ( void ) : string
final private Error::__clone ( void ) : void
}

AssertionError: It is thrown when an assertion made using assert() fails.

Description / Descripción
AssertionError extends Error {
/* Métodos heredados */
final public Error::getMessage ( void ) : string
final public Error::getPrevious ( void ) : Throwable
final public Error::getCode ( void ) : mixed
final public Error::getFile ( void ) : string
final public Error::getLine ( void ) : int
final public Error::getTrace ( void ) : array
final public Error::getTraceAsString ( void ) : string
public Error::__toString ( void ) : string
final private Error::__clone ( void ) : void
}

DivisionByZeroError: It is thrown when attempting to divide a number by zero.

Description / Descripción
DivisionByZeroError extends ArithmeticError {
/* Métodos heredados */
final public Error::getMessage ( void ) : string
final public Error::getPrevious ( void ) : Throwable
final public Error::getCode ( void ) : mixed
final public Error::getFile ( void ) : string
final public Error::getLine ( void ) : int
final public Error::getTrace ( void ) : array
final public Error::getTraceAsString ( void ) : string
public Error::__toString ( void ) : string
final private Error::__clone ( void ) : void
}

ParseError: It is thrown when an error occurs while parsing PHP code, such as when calling eval().

Description / Descripción
ParseError extends Error {
/* Métodos heredados */
final public Error::getMessage ( void ) : string
final public Error::getPrevious ( void ) : Throwable
final public Error::getCode ( void ) : mixed
final public Error::getFile ( void ) : string
final public Error::getLine ( void ) : int
final public Error::getTrace ( void ) : array
final public Error::getTraceAsString ( void ) : string
public Error::__toString ( void ) : string
final private Error::__clone ( void ) : void
}

TypeError: can be thrown for the following 3 reasons:

  • The type of argument passed to a function does not match its corresponding declared parameter type.
  • A value returned from a function does not match the declared return type of the function.
  • When an invalid number of arguments is provided to a built-in PHP function (only in strict mode).
Description / Descripción
TypeError extends Error {
/* Métodos heredados */
final public Error::getMessage ( void ) : string
final public Error::getPrevious ( void ) : Throwable
final public Error::getCode ( void ) : mixed
final public Error::getFile ( void ) : string
final public Error::getLine ( void ) : int
final public Error::getTrace ( void ) : array
final public Error::getTraceAsString ( void ) : string
public Error::__toString ( void ) : string
final private Error::__clone ( void ) : void
}

References:

Category: en-php
Something wrong? If you found an error or mistake in the content you can contact me on Twitter | @luisg2249_luis.
Last 4 post in same category

Comments