
jesteś tutaj�
453
Obsługa wyjątków
Zgłaszanie wyjątku SQLError
Na tym etapie masz już dodaną klasę
SQLError
w pliku DBcm.py, co pokazano poniżej.
import mysql.connector
class ConnectionError(Exception):
pass
class CredentialsError(Exception):
pass
class SQLError(Exception):
pass
class UseDatabase:
def __init__(self, config: dict) -> None:
self.configuration = config
...
To jest miejsce, w którym
dodałeś wyjątek SQLError.
def __exit__(self, exc_type, exc_value, exc_traceback):
self.conn.commit()
self.cursor.close()
self.conn.close()
if exc_type is mysql.connector.errors.ProgrammingError:
raise SQLError(exc_value)
...
self.conn.close()
if exc_type