Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
DBError
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * @license GPL-2.0-or-later
4 * @file
5 */
6namespace Wikimedia\Rdbms;
7
8use RuntimeException;
9
10/**
11 * Database error base class.
12 *
13 * Catching and silencing this class or its subclasses is strongly discouraged.
14 * Most code should not catch DB errors at all,
15 * but let them bubble to the MediaWiki exception handler.
16 * If necessary, cleanup can be done in a finally block;
17 * catching the exception and then rethrowing it is also acceptable.
18 *
19 * @newable
20 * @ingroup Database
21 */
22class DBError extends RuntimeException {
23    /** @var IDatabase|null */
24    public $db;
25
26    /**
27     * Construct a database error
28     * @stable to call
29     * @param IDatabase|null $db Object which threw the error
30     * @param string $error A simple error message to be used for debugging
31     * @param \Throwable|null $prev Previous throwable
32     */
33    public function __construct( ?IDatabase $db, $error, ?\Throwable $prev = null ) {
34        parent::__construct( $error, 0, $prev );
35        $this->db = $db;
36    }
37}