我正在使用 pylint 来检查我的一个 .py 脚本,并显示以下警告:
W0703: Catching too general exception Exception (broad-except)
这是代码的摘录。
try:
# Execute function1
function1()
logger.info('Function 1 successfully executed')
except Exception as e:
send_mail_error(str(e))
logger.error(str(e))
我想了解 pylint 在这里建议什么,以便改进它。
最佳答案
捕获特定异常是一个很好的做法,请阅读 here .
在您的情况下,您想要记录未知异常并发送电子邮件。在这种情况下,我使用 SMTPHandler
和自定义 sys.excepthook
- like this .
关于python - W0703 : Catching too general exception Exception (broad-except),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68485758/