Is it possible to distinguish between different unnamed exceptions in Python?

Viewed 46

I am working with a Python library, specifically a function that runs a SQL query in a database. This function has a bad habit of throwing generic Exceptions when it fails. For example, when I don't have rights to query a database, I see this error:

 Exception: None: b'You may not submit queries to this connection'

When there is an error in the query, I get this error:

Exception: None: During query 'SELECT count(*) as count from customers where birthdate=0':
Operand type clash: date is incompatible with tinyint, caused by: SQLServerException:
Operand type clash: date is incompatible with tinyint

I would like to handle the connection error differently from the query error, but I don't know how to distinguish between them because they don't have a specific type.

0 Answers
Related