avoid throwing the same type of new db exception.

This commit is contained in:
Qiang Xue
2013-11-27 23:35:43 -05:00
parent bb6b75e794
commit 3b5768b40a

View File

@ -278,9 +278,13 @@ class Command extends \yii\base\Component
return $n; return $n;
} catch (\Exception $e) { } catch (\Exception $e) {
Yii::endProfile($token, __METHOD__); Yii::endProfile($token, __METHOD__);
$message = $e->getMessage() . "\nThe SQL being executed was: $rawSql"; if ($e instanceof Exception) {
$errorInfo = $e instanceof \PDOException ? $e->errorInfo : null; throw $e;
throw new Exception($message, $errorInfo, (int)$e->getCode(), $e); } else {
$message = $e->getMessage() . "\nThe SQL being executed was: $rawSql";
$errorInfo = $e instanceof \PDOException ? $e->errorInfo : null;
throw new Exception($message, $errorInfo, (int)$e->getCode(), $e);
}
} }
} }
@ -411,9 +415,13 @@ class Command extends \yii\base\Component
return $result; return $result;
} catch (\Exception $e) { } catch (\Exception $e) {
Yii::endProfile($token, __METHOD__); Yii::endProfile($token, __METHOD__);
$message = $e->getMessage() . "\nThe SQL being executed was: $rawSql"; if ($e instanceof Exception) {
$errorInfo = $e instanceof \PDOException ? $e->errorInfo : null; throw $e;
throw new Exception($message, $errorInfo, (int)$e->getCode(), $e); } else {
$message = $e->getMessage() . "\nThe SQL being executed was: $rawSql";
$errorInfo = $e instanceof \PDOException ? $e->errorInfo : null;
throw new Exception($message, $errorInfo, (int)$e->getCode(), $e);
}
} }
} }