我正试图捕捉和计算重复输入的异常。
1062 (23000): Duplicate entry '' for key 'tabale.item_UNIQUE'
下面是产生重复项目异常的代码。
stmt='INSERT INTO table.items(item) VALUES("iteratorI");'
mc.execute(stmt)
conn.commit()
except pymysql.IntegrityError as e:
duplicateCounter=duplicateCounter+1
except Exception as ee:
otherErrors=otherErrors+1
我希望能够单独计算重复项目的例外情况,以保持对其他例外情况的计算。
我想确保我正在计算的异常是关于重复的条目,而不是其他。
另一个问题是,目前 duplicateCounter 的结果是零,尽管我得到了至少 10 个 1062 异常,这些异常被计入了 otherErrors 中。