|
Predefined ExceptionsTable of Contents
See also the SPL Exceptions ExceptionIntroductionException is the base class for all Exceptions in PHP 5, and the base class for all user exceptions in PHP 7. In PHP 7, Exception implements the Throwable interface. Class synopsisException
class Exception
{
/* 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 string getMessage
( void
)
final public Throwable getPrevious
( void
)
final public mixed getCode
( void
)
final public string getFile
( void
)
final public int getLine
( void
)
final public array getTrace
( void
)
final public string getTraceAsString
( void
)
public string __toString
( void
)
final private void __clone
( void
)
}Properties
ErrorExceptionIntroductionAn Error Exception. Class synopsisErrorException
class 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 int getSeverity
( void
)
/* Inherited methods */
final public string Exception::getMessage
( void
)
final public Throwable Exception::getPrevious
( void
)
final public mixed Exception::getCode
( void
)
final public string Exception::getFile
( void
)
final public int Exception::getLine
( void
)
final public array Exception::getTrace
( void
)
final public string Exception::getTraceAsString
( void
)
public string Exception::__toString
( void
)
final private void Exception::__clone
( void
)
}Properties
Examples
Example #1 Use set_error_handler to change error messages into ErrorException.
<?php The above example will output something similar to: Fatal error: Uncaught exception 'ErrorException' with message 'strpos() expects at least 2 parameters, 0 given' in /home/bjori/tmp/ex.php:12 Stack trace: #0 [internal function]: exception_error_handler(2, 'strpos() expect...', '/home/bjori/php...', 12, Array) #1 /home/bjori/php/cleandocs/test.php(12): strpos() #2 {main} thrown in /home/bjori/tmp/ex.php on line 12 ErrorIntroductionError is the base class for all internal PHP errors. Class synopsisError
class 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 string getMessage
( void
)
final public Throwable getPrevious
( void
)
final public mixed getCode
( void
)
final public string getFile
( void
)
final public int getLine
( void
)
final public array getTrace
( void
)
final public string getTraceAsString
( void
)
public string __toString
( void
)
final private void __clone
( void
)
}Properties
ArithmeticErrorIntroductionArithmeticError is thrown when an error occurs while performing mathematical operations. In PHP 7.0, 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 integer. Class synopsisArithmeticError
class ArithmeticError
extends
Error
{
/* Inherited methods */
final public string Error::getMessage
( void
)
final public Throwable Error::getPrevious
( void
)
final public mixed Error::getCode
( void
)
final public string Error::getFile
( void
)
final public int Error::getLine
( void
)
final public array Error::getTrace
( void
)
final public string Error::getTraceAsString
( void
)
public string Error::__toString
( void
)
final private void Error::__clone
( void
)
}AssertionErrorIntroductionAssertionError is thrown when an assertion made via assert fails. Class synopsisAssertionError
class AssertionError
extends
Error
{
/* Inherited methods */
final public string Error::getMessage
( void
)
final public Throwable Error::getPrevious
( void
)
final public mixed Error::getCode
( void
)
final public string Error::getFile
( void
)
final public int Error::getLine
( void
)
final public array Error::getTrace
( void
)
final public string Error::getTraceAsString
( void
)
public string Error::__toString
( void
)
final private void Error::__clone
( void
)
}DivisionByZeroErrorIntroductionDivisionByZeroError is thrown when an attempt is made to divide a number by zero. Class synopsisDivisionByZeroError
class DivisionByZeroError
extends
ArithmeticError
{
/* Inherited methods */
final public string Error::getMessage
( void
)
final public Throwable Error::getPrevious
( void
)
final public mixed Error::getCode
( void
)
final public string Error::getFile
( void
)
final public int Error::getLine
( void
)
final public array Error::getTrace
( void
)
final public string Error::getTraceAsString
( void
)
public string Error::__toString
( void
)
final private void Error::__clone
( void
)
}ParseErrorIntroductionParseError is thrown when an error occurs while parsing PHP code, such as when eval is called. Class synopsisParseError
class ParseError
extends
Error
{
/* Inherited methods */
final public string Error::getMessage
( void
)
final public Throwable Error::getPrevious
( void
)
final public mixed Error::getCode
( void
)
final public string Error::getFile
( void
)
final public int Error::getLine
( void
)
final public array Error::getTrace
( void
)
final public string Error::getTraceAsString
( void
)
public string Error::__toString
( void
)
final private void Error::__clone
( void
)
}TypeErrorIntroductionThere are three scenarios where a TypeError may be thrown. The first is where the argument type being passed to a function does not match its corresponding declared parameter type. The second is where a value being returned from a function does not match the declared function return type. The third is where an invalid number of arguments are passed to a built-in PHP function (strict mode only). Class synopsisTypeError
class TypeError
extends
Error
{
/* Inherited methods */
final public string Error::getMessage
( void
)
final public Throwable Error::getPrevious
( void
)
final public mixed Error::getCode
( void
)
final public string Error::getFile
( void
)
final public int Error::getLine
( void
)
final public array Error::getTrace
( void
)
final public string Error::getTraceAsString
( void
)
public string Error::__toString
( void
)
final private void Error::__clone
( void
)
} |