Current Location: Home> Function Categories> getPrevious

getPrevious

If this exception is triggered by another exception, this method returns the previous exception. If not, return null.
Name:getPrevious
Category:Uncategorized
Programming Language:php
One-line Description:If this exception is triggered by another exception, this method returns the previous exception. If not, return null.

Definition and usage

If the exception is triggered by another exception, getPrevious() method will return another exception. Otherwise, return null.

Related pages

Tutorial: PHP exception

Example

Get information about the 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 ) {  
  $previous = $e2 -> getPrevious ( ) ;  
  echo $previous -> getMessage ( ) ;  
}  
?>

Try it yourself

grammar

 $exception -> getPrevious ( )
Similar Functions
Popular Articles