PHP Exception getPrevious() Method

❮ PHP Exception Reference

Example

Get information about a previous 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();
}
?>
Try it Yourself »

Definition and Usage

If the exception was triggered by another one, then the getPrevious() method returns the other exception. Otherwise it returns null.


Syntax

$exception->getPrevious()

Technical Details

Return Value: Returns an integer

Related Pages

Read more about Exceptions in our PHP Exceptions Chapter.


❮ PHP Exception Reference
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.