/**
  * Retrieve stacktrace from cause if set or from self otherwise.
  *
  * @return  lang.StackTraceElement[] array of stack trace elements
  * @see     xp://lang.StackTraceElement
  */
 public function getStackTrace()
 {
     if (NULL !== $this->cause) {
         return $this->cause->getStackTrace();
     }
     return parent::getStackTrace();
 }
Exemplo n.º 2
0
 /**
  * Wraps an exception inside a throwable
  *
  * @param  lang.Throwable|php.Throwable|php.Exception $e
  * @return self
  * @throws lang.IllegalArgumentException
  */
 public static function wrap($e) : self
 {
     if ($e instanceof self) {
         return $e;
     } else {
         if ($e instanceof \Exception) {
             $wrapped = new XPException($e->getMessage(), $e->getPrevious(), false);
             $wrapped->addStackTraceFor($e->getFile(), '<native>', get_class($e), $e->getLine(), [$e->getCode(), $e->getMessage()], [['' => 1]]);
             $wrapped->fillInStackTrace($e);
             return $wrapped;
         } else {
             if ($e instanceof \Throwable) {
                 $wrapped = new Error($e->getMessage(), $e->getPrevious(), false);
                 $wrapped->addStackTraceFor($e->getFile(), '<native>', get_class($e), $e->getLine(), [$e->getCode(), $e->getMessage()], [['' => 1]]);
                 $wrapped->fillInStackTrace($e);
                 return $wrapped;
             } else {
                 throw new IllegalArgumentException('Given argument must be a lang.Throwable or a PHP base exception');
             }
         }
     }
 }
 /**
  * Constructor
  *
  * @param   webservices.xmlrpc.XmlRpcFault fault
  */
 public function __construct($fault)
 {
     parent::__construct($fault->faultString);
     $this->fault = $fault;
 }
 /**
  * Constructor
  *
  * @param   string message
  * @param   int statusCode default HttpConstants::STATUS_INTERNAL_SERVER_ERROR
  * @param   lang.Throwable cause
  */
 public function __construct($message, $statusCode = HttpConstants::STATUS_INTERNAL_SERVER_ERROR, $cause = NULL)
 {
     parent::__construct($message, $cause);
     $this->statusCode = $statusCode;
 }
 /**
  * Constructor
  *
  * @param   string message
  * @param   string detail
  */
 public function __construct($message, $detail)
 {
     parent::__construct($message);
     $this->detail = $detail;
 }
 /**
  * Constructor
  *
  * @param   string message
  * @param   string[] errors default array()
  */
 public function __construct($message, $errors = array())
 {
     parent::__construct($message);
     $this->errors = $errors;
 }
 /**
  * Constructor
  *
  * @param   string message
  * @param   int statuscode
  */
 public function __construct($message, $statuscode = 0)
 {
     parent::__construct($message);
     $this->statuscode = $statuscode;
 }
 /**
  * Constructor
  *
  * @param   string message
  * @param   string method
  * @see     xp://lang.XPException#construct
  */
 public function __construct($message, $method)
 {
     parent::__construct($message);
     $this->method = $method;
 }
 /**
  * Constructor
  *
  * @param  string $failedClass
  * @param  lang.IClassLoader[] $loaders default []
  * @param  lang.Throwable $cause default NULL
  */
 public function __construct($failedClass, $loaders = [], $cause = null)
 {
     parent::__construct(sprintf($this->message(), $failedClass) . ($cause ? ': ' . $cause->getMessage() : ''), $cause);
     $this->failedClass = $failedClass;
     $this->loaders = $loaders;
 }
 /**
  * Constructor
  *
  * @param   string message the error-message
  * @param   int code the error-code
  */
 public function __construct($message, $code)
 {
     parent::__construct($message);
     $this->code = $code;
 }
 /**
  * Constructor
  *
  * @param   string message
  * @param   lang.Throwable cause 
  * @param   array prerequisites default array()
  */
 public function __construct($message, Throwable $cause = NULL, $prerequisites = array())
 {
     parent::__construct($message, $cause);
     $this->prerequisites = (array) $prerequisites;
 }
 /**
  * Constructor
  *
  * @param   string classname
  */
 public function __construct($classname)
 {
     parent::__construct('(null)', $cause = NULL);
     $this->referencedClassname = $classname;
 }
 public function chainedWithUncommonElements()
 {
     $trace = array(new StackTraceElement('Test.class.php', 'Test', 'test', 0, array(), NULL), new StackTraceElement('TestSuite.class.php', 'TestSuite', '__construct', 0, array('Test::test'), NULL));
     $e = new XPException('Test');
     $e->trace = $trace;
     $c = new ChainedException($e->getMessage(), $e);
     $c->trace = array_merge(array(new StackTraceElement(NULL, 'ReflectionMethod', 'invokeArgs', 0, array(), NULL)), array(new StackTraceElement('Method.class.php', 'Method', 'invoke', 0, array(), NULL)), $trace);
     $this->assertEquals(1, preg_match_all('/  ... [0-9]+ more/', $c->toString(), $matches), $c->toString());
 }
 /**
  * Constructor
  *
  * @param   string message
  * @param   string errorcode
  * @param   var actual default NULL
  * @param   var expect default NULL
  */
 public function __construct($message, $actual = NULL, $expect = NULL)
 {
     parent::__construct((string) $message);
     $this->actual = $actual;
     $this->expect = $expect;
 }