1

I'm doing this bit of code:

try:
    cursor.execute(something)
except Exception as e:
    print(e)
    cursor.execute(something_else)
    print(cursor.fetchone())

And I've read / told that using except Exception is "too broad" and one should specify what errors they're expecting and using the broad one at the end. However, I don't know what to put as the type of error I get, because when I print(e), I have this: ('23000', "[23000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Violation of PRIMARY KEY constraint 'PK_DONNEUR_1'. Cannot insert duplicate key in object 'dbo.DONNEUR'. The duplicate key value is (49564). (2627) (SQLExecDirectW); [23000] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]The statement has been terminated. (3621)") which obviously would change based on my request. How do I make a "general error type" out of this one? Is there a way to find what to put in except (not only for SQL based errors ?).

Thanks!

0 Answers0