Zend_Exception-Previous.xml 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- Reviewed: no -->
  3. <sect1 id="zend.exception.previous">
  4. <title>Previous Exceptions</title>
  5. <para>
  6. Since Zend Framework 1.10, <classname>Zend_Exception</classname> implements the PHP 5.3
  7. support for previous exceptions. Simply put, when in a <methodname>catch</methodname>
  8. block, you can throw a new exception that references the original exception, which helps
  9. provide additional context when debugging. By providing this support in Zend Framework, your
  10. code may now be forwards compatible with PHP 5.3.
  11. </para>
  12. <para>
  13. Previous exceptions are indicated as the third argument to an exception constructor.
  14. </para>
  15. <example id="zend.exception.previous.example">
  16. <title>Previous exceptions</title>
  17. <programlisting language="php"><![CDATA[
  18. try {
  19. $db->query($sql);
  20. } catch (Zend_Db_Statement_Exception $e) {
  21. if ($e->getPrevious()) {
  22. echo '[' . get_class($e)
  23. . '] has the previous exception of ['
  24. . get_class($e->getPrevious())
  25. . ']' . PHP_EOL;
  26. } else {
  27. echo '[' . get_class($e)
  28. . '] does not have a previous exception'
  29. . PHP_EOL;
  30. }
  31. echo $e;
  32. // displays all exceptions starting by the first thrown
  33. // exception if available.
  34. }
  35. ]]></programlisting>
  36. </example>
  37. </sect1>
  38. <!--
  39. vim:se ts=4 sw=4 et:
  40. -->