I'd like to catch any type of error in Python3.
I'm trying something like that:
try:
fields = line.split(' ')
...
<PostgreSQL query execution>
except psycopg2.Error:
conn.rollback()
QUERY = "UPDATE table SET error='sql'"
cur = conn.cursor()
cur.execute(QUERY)
conn.commit()
cur.close()
continue
except:
conn.rollback()
e="generic"
QUERY = "UPDATE table SET error='generic'"
cur = conn.cursor()
cur.execute(QUERY)
conn.commit()
cur.close()
continue
But I noted that, for example, an IndexError is not caught and the script fails.
What's wrong?
Thanks!