Zend_Exception.xml 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.exception.using">
  4. <title>Using Exceptions</title>
  5. <para>
  6. <classname>Zend_Exception</classname> is simply the base class for all exceptions thrown
  7. within Zend Framework.
  8. </para>
  9. <example id="zend.exception.using.example">
  10. <title>Catching an Exception</title>
  11. <para>
  12. The following code listing demonstrates how to catch an exception thrown in a Zend
  13. Framework class:
  14. </para>
  15. <programlisting language="php"><![CDATA[
  16. try {
  17. // Calling Zend_Loader::loadClass() with a non-existant class will cause
  18. // an exception to be thrown in Zend_Loader:
  19. Zend_Loader::loadClass('nonexistantclass');
  20. } catch (Zend_Exception $e) {
  21. echo "Caught exception: " . get_class($e) . "\n";
  22. echo "Message: " . $e->getMessage() . "\n";
  23. // Other code to recover from the error
  24. }
  25. ]]></programlisting>
  26. </example>
  27. <para>
  28. <classname>Zend_Exception</classname> can be used as a catch-all exception class in a
  29. catch block to trap all exceptions thrown by Zend Framework classes. This can
  30. be useful when the program can not recover by catching a specific exception type.
  31. </para>
  32. <para>
  33. The documentation for each Zend Framework
  34. component and class will contain specific information on which methods
  35. throw exceptions, the circumstances that cause an exception to be thrown,
  36. and the various exception types that may be thrown.
  37. </para>
  38. </sect1>
  39. <!--
  40. vim:se ts=4 sw=4 et:
  41. -->