Since: 2.0
Author: Qiang Xue (qiang.xue@gmail.com)
Inheritance: extends yii\base\Exception
Exemple #1
0
 /**
  * Converts a DB exception to a more concrete one if possible.
  *
  * @param \Exception $e
  * @param string $rawSql SQL that produced exception
  * @return Exception
  */
 public function convertException(\Exception $e, $rawSql)
 {
     if ($e instanceof Exception) {
         return $e;
     }
     $exceptionClass = '\\yii\\db\\Exception';
     foreach ($this->exceptionMap as $error => $class) {
         if (strpos($e->getMessage(), $error) !== false) {
             $exceptionClass = $class;
         }
     }
     $message = $e->getMessage() . "\nThe SQL being executed was: {$rawSql}";
     $errorInfo = $e instanceof \PDOException ? $e->errorInfo : null;
     return new $exceptionClass($message, $errorInfo, (int) $e->getCode(), $e);
 }
Exemple #2
0
 /**
  * @param \Throwable|\Exception $e
  */
 private function printException($e)
 {
     echo 'Exception: ' . $e->getMessage() . ' (' . $e->getFile() . ':' . $e->getLine() . ")\n";
     echo $e->getTraceAsString() . "\n";
 }