12.9. Catching Gdata Exceptions
Prev | Chapter 12. Zend_Gdata | Next

## 12.9. Catching Gdata Exceptions

The `Zend_Gdata_Exception` class is a base class for exceptions thrown by Zend_Gdata. You can catch any exception thrown by Zend_Gdata by catching Zend_Gdata_Exception.

    <?php
    try {
        $client = Zend_Gdata_ClientLogin::getHttpClient($username, $password);
    } catch(Zend_Gdata_Exception $ex) {
        // Report the exception to the user
        die($ex->getMessage());
    }
    ?>

The following exception subclasses are used by Zend_Gdata:

- `Zend_Gdata_AuthException` indicates that the user's account credentials were not valid.

- `Zend_Gdata_BadMethodCallException` indicates that a method was called for a service that does not support the method. For example, the CodeSearch service does not support `post()`.

- `Zend_Gdata_HttpException` indicates that an HTTP request was not successful.

- `Zend_Gdata_InvalidArgumentException` is thrown when the application provides a value that is not valid in a given context. For example, specifying a Calendar visibility value of "banana", or fetching a Blogger feed without specifying any blog name.

You can use these exception subclasses to handle specific exceptions differently. See the API documentation for information on which exception subclasses are thrown by which methods in Zend_Gdata.

    <?php
    try {
        $client = Zend_Gdata_ClientLogin::getHttpClient($username, $password);
    } catch(Zend_Gdata_AuthException $authEx) {
        // The user's credentials were incorrect.
        // It would be appropriate to give the user a second try.
        ...
    } catch(Zend_Gdata_HttpException $httpEx) {
        // Google Data servers cannot be contacted.
        die($httpEx->getMessage);
    }
    ?>

Prev | Up | Next
12.8. Using the Gdata Data Helper | Home | Chapter 13. Zend_Http