Documentation

Previous Exceptions - Zend_Exception

Previous Exceptions

Since Zend Framework 1.10, Zend_Exception implements the PHP 5.3 support for previous exceptions. Simply put, when in a catch() block, you can throw a new exception that references the original exception, which helps provide additional context when debugging. By providing this support in Zend Framework, your code may now be forwards compatible with PHP 5.3.

Previous exceptions are indicated as the third argument to an exception constructor.

Example #1 Previous exceptions

  1. try {
  2.     $db->query($sql);
  3. } catch (Zend_Db_Statement_Exception $e) {
  4.     if ($e->getPrevious()) {
  5.         echo '[' . get_class($e)
  6.             . '] has the previous exception of ['
  7.             . get_class($e->getPrevious())
  8.             . ']' . PHP_EOL;
  9.     } else {
  10.         echo '[' . get_class($e)
  11.             . '] does not have a previous exception'
  12.             . PHP_EOL;
  13.     }
  14.  
  15.     echo $e;
  16.     // displays all exceptions starting by the first thrown
  17.     // exception if available.
  18. }

Previous topic

Basic usage

Next topic

Zend_Feed

Copyright

© 2006-2021 by Zend by Perforce. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts