Curriculum
Course: PHP Basic
Login

Curriculum

PHP Basic

PHP Install

0/1

PHP Casting

0/1

PHP Constants

0/1

PHP Magic Constants

0/1

PHP Operators

0/1

PHP Reference

0/276
Text lesson

PHP Exception

PHP Exception Object

Exceptions are used by functions and methods to communicate errors and unexpected behavior.

The Exception object does not have public properties but contains private and protected properties that can be accessed via the constructor and methods.

The Exception object provides the following methods:

Method

Description

Exception()

The constructor of the Exception object

getCode()

Returns the exception code

getFile()

Returns the full path of the file where the exception was thrown.

getMessage()

Returns a string explaining why the exception was thrown.

getLine()

Returns the line number where the exception was thrown.

getPrevious()

If this exception was caused by another exception, this method returns the previous exception; otherwise, it returns null.

getTrace()

Returns an array containing information about all the functions that were executing when the exception was thrown.

getTraceAsString()

Returns the same information as getTrace(), but formatted as a string.