<?php
namespace nur\sery\db\sqlite;

use Exception;
use RuntimeException;
use SQLite3;

class SqliteException extends RuntimeException {
  static final function check(SQLite3 $db, $value, bool $throw=true) {
    if ($value !== false) return $value;
    elseif (!$throw) return null;
    else throw new static($db->lastErrorMsg(), $db->lastErrorCode());
  }

  static final function wrap(Exception $e): self{
    return new static($e->getMessage(), $e->getCode(), $e);
  }
}
