19.1. Using Exceptions

Zend_Exception is simply the base class for all exceptions thrown within Zend Framework.

Example 19.1. Catching an Exception

The following code listing demonstrates how to catch an exception thrown in a Zend Framework class:

try {
    // Calling Zend_Loader::loadClass() with a non-existant class will cause
    // an exception to be thrown in Zend_Loader
} catch (Zend_Exception $e) {
    echo "Caught exception: " . get_class($e) . "\n";
    echo "Message: " . $e->getMessage() . "\n";
    // Other code to recover from the error

Zend_Exception can be used as a catch-all exception class in a catch block to trap all exceptions thrown by Zend Framework classes. This can be useful when the program can not recover by catching a specific exception type.

The documentation for each Zend Framework component and class will contain specific information on which methods throw exceptions, the circumstances that cause an exception to be thrown, and the class of all exceptions that may be thrown.

Table of Contents

19.1. Using Exceptions

Previous topic


Next topic



© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

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