# Exception

> Exception represents an exception that is caused by some DB-related operations.

[API reference](/docs/api/index.md) › [yii](/docs/api/yii/index.md) › [db](/docs/api/yii/db/index.md) › Exception

| class | `yii\db\Exception` |
| --- | --- |
| Extends | [`yii\base\Exception`](/docs/api/yii/base/exception/index.md) » [`Exception`](https://www.php.net/manual/en/class.exception.php) |
| Since | 2.0 |
| Source | [`framework/db/Exception.php`](https://github.com/yiisoft/yii2/blob/22.0/framework/db/Exception.php#L17) |

2 subclasses:

- [`IntegrityException`](/docs/api/yii/db/integrityexception/index.md)
- [`StaleObjectException`](/docs/api/yii/db/staleobjectexception/index.md)

Exception represents an exception that is caused by some DB-related operations.

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| [`$errorInfo`](#property-errorInfo) | `array` | The error info provided by a PDO exception. Default: `[]`. | `Exception` |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) | Constructor. | `Exception` |
| [`__toString()`](#method-__toString) |  | `Exception` |
| [`getName()`](#method-getName) |  | `Exception` |

## Property details

### $errorInfo <span id="property-errorInfo"></span>

```php
public array $errorInfo = []
```

The error info provided by a PDO exception.

This is the same as returned
by [PDO::errorInfo](https://www.php.net/manual/en/pdo.errorinfo.php).

## Method details

### __construct() <span id="method-__construct"></span>

```php
public function __construct(string $message, array $errorInfo = [], string $code = '', Throwable|null $previous = null)
```

Constructor.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$message` | `string` | PDO error message |
| `$errorInfo` | `array` | PDO error info |
| `$code` | `string` | PDO error code |
| `$previous` | [`Throwable`](https://www.php.net/manual/en/class.throwable.php)`\|null` | The previous exception used for the exception chaining. |

### __toString() <span id="method-__toString"></span>

```php
public function __toString(): string
```

**Returns**

`string`: Readable representation of exception

### getName() <span id="method-getName"></span>

```php
public function getName(): string
```

**Returns**

`string`: The user-friendly name of this exception