我遇到了try-except方法的问题,我想通过将这些错误发送到我的邮件来监视脚本中的任何错误,该脚本只检查文件存在,它看起来像:在Python中尝试除外法错误
def check_file_existence():
try:
with open('\\\\ntsrv1\\tohna\\SecurityTeam\\Varonis\\Varonis_monitoring_report\\Varonis_Action_Report.csv', 'r') as temp_file:
temp_file.close()
except ValueError as e:
e = str(e)
print(e)
status_mail_notofication('error in move_report_to_folder_adding_date_to_file Function under varonis_report_analysis script ','there was an error in check_file_existence Function','[email protected]')
sys.exit(0)
return
运行与目的的代码来得到一个错误
后,我得到这个:
IO错误:[错误2]没有这样的文件或目录:“\\ ntsrv1 \ tohna \ SecurityTeam \ Varonis \ Varonis_monitoring_report \ Varonis_Action_Report.csv'
,它并没有去除了一部分,我需要得到邮件与错误,它只是停止
人知道为什么吗?
TNX
为什么'ValueError'会捕获IOError?你选择性地试图处理前者,而后者应该提出异议。 – roganjosh