Python Glossary Русский

all Python 3sqlite3exception

sqlite3.Warning

exceptions

The DB-API exception for database warnings. The sqlite3 module itself no longer raises it — the class is kept for PEP 249 compliance.

Syntax

sqlite3.Warning

Despite the name it is not a warning: sqlite3.Warning derives from Exception, not from the built-in Warning, so warnings.filterwarnings ignores it and except Warning will not catch it. Up to Python 3.10, execute() raised it for a string with two SQL statements; since 3.11 that is ProgrammingError, so old except sqlite3.Warning clauses no longer fire. In 3.14 the class is not deprecated, it is simply never raised by the module.

Examples

import sqlite3
print(issubclass(sqlite3.Warning, Exception))  # → True
print(issubclass(sqlite3.Warning, Warning))  # → False — это не встроенный Warning
print(issubclass(sqlite3.Warning, sqlite3.Error))  # → False
# Python 3.11+
import sqlite3
conn = sqlite3.connect(':memory:')
try:
    conn.execute('SELECT 1; SELECT 2')
except sqlite3.Warning:
    print('Warning')
except sqlite3.ProgrammingError as e:
    print(type(e).__name__)  # → ProgrammingError — с 3.11, раньше был Warning
conn.close()

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy