Final Class Yiisoft\Db\Exception\ConvertException
| Inheritance | Yiisoft\Db\Exception\ConvertException |
|---|
Converts an exception into a more specific one.
For example, if an exception is caused by a violation of a unique key constraint, it will be converted into an {@see \Yiisoft\Db\Exception\IntegrityException} exception.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\Db\Exception\ConvertException | |
| run() | Converts an exception into a more specific one. | Yiisoft\Db\Exception\ConvertException |
Constants
| Constant | Value | Description | Defined By |
|---|---|---|---|
| MGS_INTEGRITY_EXCEPTION_2 | 'ORA-00001: unique constraint' | Yiisoft\Db\Exception\ConvertException | |
| MSG_INTEGRITY_EXCEPTION_1 | 'SQLSTATE[23' | Yiisoft\Db\Exception\ConvertException | |
| MSG_INTEGRITY_EXCEPTION_3 | 'SQLSTATE[HY' | Yiisoft\Db\Exception\ConvertException |
Method Details
| public mixed __construct ( Exception $e, string $rawSql ) | ||
| $e | Exception | |
| $rawSql | string | |
public function __construct(private \Exception $e, private string $rawSql) {}
Converts an exception into a more specific one.
| public Yiisoft\Db\Exception\Exception run ( ) | ||
| return | Yiisoft\Db\Exception\Exception |
The converted exception if it could be converted, otherwise the original exception. |
|---|---|---|
public function run(): Exception
{
$message = $this->e->getMessage() . PHP_EOL . 'The SQL being executed was: ' . $this->rawSql;
$errorInfo = $this->e instanceof PDOException ? $this->e->errorInfo : null;
return match (
str_contains($message, self::MSG_INTEGRITY_EXCEPTION_1)
|| str_contains($message, self::MGS_INTEGRITY_EXCEPTION_2)
|| str_contains($message, self::MSG_INTEGRITY_EXCEPTION_3)
) {
true => new IntegrityException($message, $errorInfo, $this->e),
default => new Exception($message, $errorInfo, $this->e),
};
}
Signup or Login in order to comment.