如何在 python 中捕获并显示确切的错误消息
How to catch and display the extact error message in python
我有使用 python 将数据从 excel 插入到 mysql 的代码。
我正在尝试捕获一些错误消息并向最终用户显示更清晰的信息,例如:
如果您尝试将 NaN 插入 mysql,系统会显示以下信息:
'''
1054 (42S22):'field list' 中的未知列 '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)
捕获错误信息,但不能显示显式信息。
可能我说的不对,欢迎大家指正
谢谢
很简单见manual
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")
我有使用 python 将数据从 excel 插入到 mysql 的代码。
我正在尝试捕获一些错误消息并向最终用户显示更清晰的信息,例如:
如果您尝试将 NaN 插入 mysql,系统会显示以下信息:
'''
1054 (42S22):'field list' 中的未知列 '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)
捕获错误信息,但不能显示显式信息。
可能我说的不对,欢迎大家指正
谢谢
很简单见manual
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")