我有使用python将数据从excel插入MySQL的代码。
我正在尝试捕获一些错误消息并向最终用户显示更清楚的信息,例如:
如果您试图将NaN插入到mysql中,系统将显示以下信息:
''1054(42S22):'fieldlist''''中的未知列'NaN'
如何捕获此错误消息以显示更清晰的信息,如:
if ErrorCode='1054':
print('please check at original file at see whether there is empty value at certain area"
我使用
try:
except Exception as:
print(e)
以捕获错误消息,但无法显示明确的信息。
可能是我错了,请随时联系。
谢谢。
这是相当直的战争请参阅手册
except mysql.connector.Error as err:
if err.errno == 1054:
print("please check at original file at see whether there is empty value at certain area")
else:
print("Another error")