Advertisement
Guest User

Untitled

a guest
Jul 25th, 2010
564
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.21 KB | None | 0 0
  1. if(phpversion() < 5.3){
  2.     class baseException extends Exception{
  3.  
  4.         /**
  5.          * @var Exception
  6.          */
  7.         protected $previousException;
  8.  
  9.         /**
  10.          * @param string $message
  11.          * @param int $code
  12.          * @param Exception $previous
  13.          */
  14.         function __construct($message = '', $code = 0, $previous = null) {
  15.             parent::__construct($message, 0);
  16.             $this->previousException = $previous;
  17.         }
  18.  
  19.         /**
  20.          * @return Exception
  21.          */
  22.         public function getPrevious() {
  23.             return $this->previousException;
  24.         }
  25.  
  26.         /**
  27.          * @return string
  28.          */
  29.         public function _getTraceAsString() {
  30.             if($this->previousException === null){
  31.                 return parent::getTraceAsString();
  32.             }
  33.             if($this->previousException instanceof BaseException){
  34.                 return $this->previousException->_getTraceAsString();
  35.             }
  36.             return $this->previousException->getTraceAsString();
  37.         }
  38.  
  39.         /**
  40.          * @return array
  41.          */
  42.         public function _getTrace() {
  43.             if($this->previousException === null){
  44.                 return parent::getTrace();
  45.             }
  46.             if($this->previousException instanceof BaseException){
  47.                 return $this->previousException->_getTrace();
  48.             }
  49.             return $this->previousException->getTrace();
  50.         }
  51.  
  52.         /**
  53.          * @return string
  54.          */
  55.         public function __toString() {
  56.             return "exception '".__CLASS__ ."' with message '".$this->getMessage()
  57.                 ."' in ".$this->getFile().":".$this->getLine()
  58.                 ."\nStack trace:\n".$this->_getTraceAsString();
  59.         }
  60.     }
  61. } else {
  62.     class baseException extends Exception{
  63.         public function __construct($message, $code = 0, $previous = null) {
  64.             parent::__construct($message, 0, $previous);
  65.         }
  66.  
  67.         /**
  68.          * @return string
  69.          */
  70.         public function _getTraceAsString() {
  71.             return $this->getTraceAsString();
  72.         }
  73.  
  74.         /**
  75.          * @return array
  76.          */
  77.         public function _getTrace() {
  78.             return $this->getTrace();
  79.         }
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement