Exception.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend
  17. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id$
  20. */
  21. if (version_compare(PHP_VERSION, '5.3.0', '<')) {
  22. /**
  23. * @category Zend
  24. * @package Zend
  25. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  26. * @license http://framework.zend.com/license/new-bsd New BSD License
  27. */
  28. class Zend_Exception extends Exception
  29. {
  30. /**
  31. * @var null|Exception
  32. */
  33. private $_previous = null;
  34. /**
  35. * Construct the exception
  36. *
  37. * @param string $msg
  38. * @param int $code
  39. * @param Exception $previous
  40. * @return void
  41. */
  42. public function __construct($msg = '', $code = 0, Exception $previous = null)
  43. {
  44. parent::__construct($msg, (int) $code);
  45. $this->_previous = $previous;
  46. }
  47. /**
  48. * Returns previous Exception
  49. *
  50. * @return Exception|null
  51. */
  52. final public function getPrevious()
  53. {
  54. return $this->_previous;
  55. }
  56. /**
  57. * String representation of the exception
  58. *
  59. * @return string
  60. */
  61. public function __toString()
  62. {
  63. if (null !== ($e = $this->getPrevious())) {
  64. return $e->__toString()
  65. . "\n\nNext "
  66. . parent::__toString();
  67. }
  68. return parent::__toString();
  69. }
  70. }
  71. } else {
  72. /**
  73. * @category Zend
  74. * @package Zend
  75. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  76. * @license http://framework.zend.com/license/new-bsd New BSD License
  77. */
  78. class Zend_Exception extends Exception
  79. {
  80. public function __construct($msg = '', $code = 0, Exception $previous = null)
  81. {
  82. if (!is_int($code)) {
  83. $code = (int) $code;
  84. }
  85. parent::__construct($msg, $code, $previous);
  86. }
  87. }
  88. }