Completed
Push — 2.1 ( fdad1c...481970 )
by
unknown
19:03 queued 05:08
created

Exception::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
ccs 4
cts 4
cp 1
cc 1
eloc 3
nc 1
nop 4
crap 1
1
<?php
2
/**
3
 * @link http://www.yiiframework.com/
4
 * @copyright Copyright (c) 2008 Yii Software LLC
5
 * @license http://www.yiiframework.com/license/
6
 */
7
8
namespace yii\db;
9
10
/**
11
 * Exception represents an exception that is caused by some DB-related operations.
12
 *
13
 * @author Qiang Xue <[email protected]>
14
 * @since 2.0
15
 */
16
class Exception extends \yii\base\Exception
17
{
18
    /**
19
     * @var array the error info provided by a PDO exception. This is the same as returned
20
     * by [PDO::errorInfo](http://www.php.net/manual/en/pdo.errorinfo.php).
21
     */
22
    public $errorInfo = [];
23
24
25
    /**
26
     * Constructor.
27
     * @param string $message PDO error message
28
     * @param array $errorInfo PDO error info
29
     * @param int $code PDO error code
30
     * @param \Exception $previous The previous exception used for the exception chaining.
31
     */
32 43
    public function __construct($message, $errorInfo = [], $code = 0, \Exception $previous = null)
33
    {
34 43
        $this->errorInfo = $errorInfo;
35 43
        parent::__construct($message, $code, $previous);
36 43
    }
37
38
    /**
39
     * @return string the user-friendly name of this exception
40
     */
41
    public function getName()
42
    {
43
        return 'Database Exception';
44
    }
45
46
    /**
47
     * @return string readable representation of exception
48
     */
49 3
    public function __toString()
50
    {
51 3
        return parent::__toString() . PHP_EOL
52 3
        . 'Additional Information:' . PHP_EOL . print_r($this->errorInfo, true);
53
    }
54
}
55