title: Is it possible to distinguish between different unnamed exceptions in Python?
body: <p>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:</p>
  
  <pre><code> Exception: None: b'You may not submit queries to this connection'
  </code></pre>
  
  <p>When there is an error in the query, I get this error:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>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.</p>