In response to the 15-May-2010 07:45 note from: samuelelliot+php dot net at gmail dot com
Since the most base class Exception takes three arguments, and the previous exception is not the first, ...
Since inherited classes to not implicitly call the parent constructor, ...
I recommend changing his constructor to this:
public function __construct(string $message = "", int $code = 0, PDOException $e = null)
{
// in case they call: new MyException($somePDOException);
// instead of following the interface.
//
if (is_subclass_of($message, PDOException))
{
$e = $message;
$code = $e->getCode();
$message = $e->getMessage();
}
// Let PDOException do its normal thing
//
parent::__construct($message, $code, $e);
// Now to correct the code number.
//
$state = $this->getMessage();
if(!strstr($state, 'SQLSTATE['))
$state = $this->getCode();
if(strstr($state, 'SQLSTATE['))
{
preg_match('/SQLSTATE\[(\w+)\] \[(\w+)\] (.*)/', $state, $matches);
$this->code = ($matches[1] == 'HT000' ? $matches[2] : $matches[1]);
$this->message = $matches[3];
}
}