Zend_Exception-Previous.xml 1.4 KB

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