Since: 2.0
Author: Qiang Xue (qiang.xue@gmail.com)
Inheritance: extends Exception, implements yii\base\Arrayable
Example #1
0
 /**
  * @param string $apiSubUrl
  * @param array $params
  * @param array $headers
  * @param bool $delay
  * @param bool $error
  * @return array
  * @throws \Exception
  */
 public function api($apiSubUrl, $params = [], $headers = [], $delay = false, $error = false)
 {
     $params['lang'] = 'ru';
     $countError = 0;
     $e = new \Exception();
     while ($countError < 5) {
         try {
             return parent::api($apiSubUrl, 'POST', $params, $headers, $delay)['response'];
         } catch (\Exception $e) {
             if ($error) {
                 throw $e;
             }
             if ($e->getCode()) {
                 if ($e->getCode() == 6) {
                     sleep(2);
                     return $this->api($apiSubUrl, $params, $headers, $delay, true);
                 } else {
                     throw $e;
                 }
             } elseif ($countError > 0) {
                 $this->big = true;
             }
             ++$countError;
         }
     }
     throw $e;
 }
 /**
  * Constructs the exception.
  * @link http://php.net/manual/en/errorexception.construct.php
  * @param $message [optional]
  * @param $code [optional]
  * @param $severity [optional]
  * @param $filename [optional]
  * @param $lineno [optional]
  * @param $previous [optional]
  */
 public function __construct($message = '', $code = 0, $severity = 1, $filename = __FILE__, $lineno = __LINE__, \Exception $previous = null)
 {
     parent::__construct($message, $code, $previous);
     $this->severity = $severity;
     $this->file = $filename;
     $this->line = $lineno;
     if (function_exists('xdebug_get_function_stack')) {
         $trace = array_slice(array_reverse(xdebug_get_function_stack()), 3, -1);
         foreach ($trace as &$frame) {
             if (!isset($frame['function'])) {
                 $frame['function'] = 'unknown';
             }
             // XDebug < 2.1.1: http://bugs.xdebug.org/view.php?id=695
             if (!isset($frame['type']) || $frame['type'] === 'static') {
                 $frame['type'] = '::';
             } elseif ($frame['type'] === 'dynamic') {
                 $frame['type'] = '->';
             }
             // XDebug has a different key name
             if (isset($frame['params']) && !isset($frame['args'])) {
                 $frame['args'] = $frame['params'];
             }
         }
         $ref = new \ReflectionProperty('Exception', 'trace');
         $ref->setAccessible(true);
         $ref->setValue($this, $trace);
     }
 }
 /**
  * @param string     $sourcePath
  * @param string     $destinationPath
  * @param string     $message
  * @param integer    $code
  * @param \Exception $previous
  */
 public function __construct($sourcePath, $destinationPath, $message = null, $code = 0, \Exception $previous = null)
 {
     $this->sourcePath = $sourcePath;
     $this->destinationPath = $destinationPath;
     $message = $message ?: $this->getDefaultMessage();
     parent::__construct($message, $code, $previous);
 }
 /**
  * @param array|string $url the parameter to be used to generate a valid URL for redirection.
  * This will be used as first parameter for [[\yii\helpers\Url::to()]]
  * @param integer $statusCode HTTP status code used for redirection
  * @param boolean|string $scheme the URI scheme to use in the generated URL for redirection.
  * This will be used as second parameter for [[\yii\helpers\Url::to()]]
  * @param string $message the error message
  * @param integer $code the error code
  * @param \Exception $previous the previous exception used for the exception chaining
  */
 public function __construct($url, $statusCode = 302, $scheme = false, $message = null, $code = 0, \Exception $previous = null)
 {
     $this->url = $url;
     $this->scheme = $scheme;
     $this->statusCode = $statusCode;
     parent::__construct($message, $code, $previous);
 }
Example #5
0
 /**
  * @return string readable representation of exception
  */
 public function __toString()
 {
     $string = parent::__toString() . PHP_EOL . 'Request Information:' . PHP_EOL . print_r($this->requestInfo, true);
     if (!empty($this->errorInfo)) {
         $string .= PHP_EOL . 'Error Information:' . PHP_EOL . print_r($this->errorInfo, true);
     }
     return $string;
 }
 public function __construct($message, Exception $internalException = null, $appendInternalExceptionMessage = false)
 {
     $this->_internalException = $internalException;
     if ($internalException != null && $appendInternalExceptionMessage) {
         $internalExceptionClassName = get_class($internalException);
         $message .= "\r\nInternal Exception: {$internalExceptionClassName}. Message {$internalException->getMessage()}";
     }
     parent::__construct($message);
 }
 /**
  * @param Model $entity
  */
 public function __construct(Model $entity)
 {
     $messages = [];
     $this->entity = $entity;
     foreach ($entity->errors as $attribute => $errors) {
         $messages[] = implode(' : ', ['attribute' => $attribute, 'message' => implode(', ', (array) $errors)]);
     }
     parent::__construct(implode(PHP_EOL, $messages));
 }
 /**
  * @param ActiveRecord|array $message = null
  * @param int $code = 0
  * @param \Exception $previous = null
  */
 public function __construct($message = null, $code = 0, $previous = null)
 {
     if ($message instanceof ActiveRecord) {
         $message = $message->getErrors();
     }
     if (is_array($message)) {
         $message = json_encode($message);
     }
     parent::__construct($message, $code, $previous);
 }
 /**
  * @param StandardAttribute $standardAttribute
  * {@inheritdoc}
  */
 public function __construct(StandardAttribute $standardAttribute, $message = "", $code = 0, \Exception $previous = null)
 {
     $attributeName = 'attribute';
     if ($standardAttribute->name) {
         $attributeName .= " {$standardAttribute->name}";
     }
     $modelClass = "{$standardAttribute->standardModel->className}";
     $message = "Invalid configuration for {$attributeName} in model {$modelClass}. {$message}";
     parent::__construct($message, $code, $previous);
 }
Example #10
0
 /**
  * Constructor
  *
  * @param RestfulClient $restfulClient
  */
 public function __construct(RestfulClient $restfulClient)
 {
     $this->errors = [];
     foreach ($restfulClient->getErrors() as $field => $message) {
         $this->errors[$field][] = $message;
     }
     $this->requestUrl = $restfulClient->request->getUri();
     $code = $restfulClient->getResponseCode();
     $message = $restfulClient->getResponseMsg();
     parent::__construct($message, $code);
 }
 function __construct($msg, $parser = null, $pattern = '')
 {
     $this->parser = $parser;
     $this->pattern = $pattern;
     if (!empty($parser)) {
         $msg .= ", Classname: " . get_class($parser) . ', ';
     }
     if (!empty($pattern)) {
         $msg .= ", Pattern:" . $pattern . ', ';
     }
     // @todo pass $this as 3rd arg?
     parent::__construct($msg, 0, null);
 }
 public function __construct($field, $code = 500)
 {
     parent::__construct(sprintf("field %s is missing in options list", $field), $code);
 }
 public function __construct($filterName, $code = 500)
 {
     parent::__construct(sprintf("Filter %s was not found in the filter registry", $filterName), $code);
 }
 /**
  * Renders the previous exception stack for a given Exception.
  * @param \Exception $exception the exception whose precursors should be rendered.
  * @return string HTML content of the rendered previous exceptions.
  * Empty string if there are none.
  */
 public function renderPreviousExceptions($exception)
 {
     if (($previous = $exception->getPrevious()) !== null) {
         return $this->renderFile($this->previousExceptionView, ['exception' => $previous]);
     } else {
         return '';
     }
 }
 /**
  * Renders an exception without using rich format.
  * @param \Exception $exception the exception to be rendered.
  * @return string the rendering result
  */
 public function renderException($exception)
 {
     if ($exception instanceof Exception && ($exception instanceof UserException || !YII_DEBUG)) {
         $message = $exception->getName() . ': ' . $exception->getMessage();
         if (Yii::$app->controller instanceof \yii\console\Controller) {
             $message = Yii::$app->controller->ansiFormat($message, Console::FG_RED);
         }
     } else {
         $message = YII_DEBUG ? (string) $exception : 'Error: ' . $exception->getMessage();
     }
     if (PHP_SAPI === 'cli') {
         return $message . "\n";
     } else {
         return '<pre>' . htmlspecialchars($message, ENT_QUOTES, $this->charset) . '</pre>';
     }
 }
Example #16
0
 public function __construct($message = "", $code = 0)
 {
     AngryCurl::add_debug_msg($message);
     parent::__construct($message, $code);
 }
 public function __construct($message, $id, $buttons = null)
 {
     $this->id = $id;
     $this->buttons = $buttons;
     parent::__construct($message);
 }
 /**
  * Constructor of the exception.
  * 
  * @param Model $model
  * @param \Exception $previous
  */
 public function __construct(Model $model, \Exception $previous = null)
 {
     $message = 'Unable to save ' . get_class($model) . '. Errors: [' . Json::encode($model->getErrors()) . ']';
     parent::__construct($message, 1100, $previous);
 }
Example #19
0
 public function __construct($message, $code, $exception = null, $method = null)
 {
     $this->exception = $exception;
     $this->method = $method;
     parent::__construct($message, $code);
 }
 public function __construct($field)
 {
     parent::__construct(sprintf("Param \"%s\" is required", $field));
 }
 public function __construct($validation, $message = null)
 {
     $this->validation = $validation;
     parent::__construct($message);
 }
Example #22
0
 /**
  * @return string readable representation of exception
  */
 public function __toString()
 {
     return parent::__toString() . PHP_EOL . 'Additional Information:' . PHP_EOL . print_r($this->errorInfo, true);
 }
Example #23
0
 public static function showException(Exception $e)
 {
     echo '<pre>';
     var_dump($e->getPrevious());
     echo '</pre>';
     exit;
 }
 /**
  * Constructor.
  * @param \yii\httpclient\Response $response response body
  * @param string $message error message
  * @param int $code error code
  * @param \Exception $previous The previous exception used for the exception chaining.
  */
 public function __construct($response, $message = null, $code = 0, \Exception $previous = null)
 {
     $this->response = $response;
     parent::__construct($message, $code, $previous);
 }
Example #25
0
 /**
  * Constructor.
  * @param array $responseHeaders response headers
  * @param string $responseBody response body
  * @param string $message error message
  * @param integer $code error code
  * @param \Exception $previous The previous exception used for the exception chaining.
  * @internal param int $status HTTP status code, such as 404, 500, etc.
  */
 public function __construct($responseHeaders, $responseBody, $message = null, $code = 0, \Exception $previous = null)
 {
     $this->responseBody = $responseBody;
     $this->responseHeaders = $responseHeaders;
     parent::__construct($message, $code, $previous);
 }
 /**
  * @param Model      $model
  * @param string     $message
  * @param integer    $code
  * @param \Exception $previous
  */
 public function __construct(Model $model, $message = null, $code = 0, \Exception $previous = null)
 {
     $this->model = $model;
     $message = $message ?: $this->getDefaultMessage();
     parent::__construct($message, $code, $previous);
 }
 public function __construct($message = "", $row = [], $code = 0, \Exception $previous = null)
 {
     $this->row = $row;
     parent::__construct($message, $code, $previous);
 }
 /**
  * PendingPurchaseException constructor
  *
  * @param string $message
  * @param AbstractPurchase $purchase
  * @param Exception $previous
  */
 public function __construct($message, $purchase, Exception $previous = null)
 {
     $this->purchase = $purchase;
     $this->position = $purchase->position;
     parent::__construct($message, 0, $previous);
 }
Example #29
0
 /**
  * Converts an exception into a simple string.
  * @param \Exception $exception the exception being converted
  * @return string the string representation of the exception.
  */
 public static function convertExceptionToString($exception)
 {
     if ($exception instanceof Exception && ($exception instanceof UserException || !YII_DEBUG)) {
         $message = "{$exception->getName()}: {$exception->getMessage()}";
     } elseif (YII_DEBUG) {
         if ($exception instanceof Exception) {
             $message = "Exception ({$exception->getName()})";
         } elseif ($exception instanceof ErrorException) {
             $message = "{$exception->getName()}";
         } else {
             $message = 'Exception';
         }
         $message .= " '" . get_class($exception) . "' with message '{$exception->getMessage()}' \n\nin " . $exception->getFile() . ':' . $exception->getLine() . "\n\n" . "Stack trace:\n" . $exception->getTraceAsString();
     } else {
         $message = 'Error: ' . $exception->getMessage();
     }
     return $message;
 }
Example #30
0
 public function __construct($message, $code, $data = null)
 {
     $this->data = $data;
     parent::__construct($message, $code);
 }