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

getPrevious()

Example

Retrieve details about a preceding exception.

<?php
try {
  try {
    throw new Exception(“An error occurred”1);
  } catch(Exception $e1) {
    throw new Exception(“Another error occurred”2, $e1);
  }

catch (Exception $e2) {
  echo $previous = $e2->getPrevious();
  echo $previous->getMessage();
}
?>

Definition and Usage

If the exception was caused by another exception, the getPrevious() method returns that previous exception; otherwise, it returns null.

Syntax

$exception->getPrevious()

Technical Details

Return Value:

Returns an integer.