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.

Previous exceptions

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

    echo $e;
    // displays all exceptions starting by the first thrown
    // exception if available.
}

Project Versions

This Page

Edit this document

Edit this document

The source code of this file is hosted on GitHub. Everyone can update and fix errors in this document with few clicks - no downloads needed.

  1. Login with your GitHub account.
  2. Go to Previous Exceptions on GitHub.
  3. Edit file contents using GitHub's text editor in your web browser
  4. Fill in the Commit message text box at the end of the page telling why you did the changes. Press Propose file change button next to it when done.
  5. On Send a pull request page you don't need to fill in text anymore. Just press Send pull request button.
  6. Your changes are now queued for review under project's Pull requests tab on GitHub.