for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
namespace Doctrine\DBAL;
use Doctrine\DBAL\Driver\DriverException as DriverExceptionInterface;
use Doctrine\DBAL\Driver\ExceptionConverterDriver;
use Doctrine\DBAL\Exception\DriverException;
use Doctrine\DBAL\Exception\FormatArray;
use Exception;
use Throwable;
use function sprintf;
class DBALException extends Exception
{
/**
* @param string $sql
* @param mixed[] $params
*
* @return self
*/
public static function driverExceptionDuringQuery(Driver $driver, Throwable $driverEx, $sql, array $params = [])
$messageFormat = <<<'MESSAGE'
An exception occurred while executing "%s"%s:
%s.
MESSAGE;
$message = sprintf(
$messageFormat,
$sql,
$params !== [] ? sprintf(' with params %s', (new FormatArray())->__invoke($params)) : '',
$driverEx->getMessage()
);
return static::wrapException($driver, $driverEx, $message);
}
public static function driverException(Driver $driver, Throwable $driverEx)
return static::wrapException($driver, $driverEx, sprintf('An exception occurred in driver with message: %s', $driverEx->getMessage()));
private static function wrapException(Driver $driver, Throwable $driverEx, $msg)
if ($driverEx instanceof DriverException) {
return $driverEx;
if ($driver instanceof ExceptionConverterDriver && $driverEx instanceof DriverExceptionInterface) {
return $driver->convertException($msg, $driverEx);
return new self($msg, 0, $driverEx);