|
python3避免python程序运行出错处理
- try
- ... # 报错的代码
- except Exception as error_report:
- print(error_report) # 把错误信息打印出来
复制代码
email错误报告
- import logging
- import logging.handlers
- smtp_handler = logging.handlers.SMTPHandler(mailhost=("smtp.example.com", 25),
- fromaddr="from@example.com",
- toaddrs="to@example.com",
- subject=u"AppName error!")
- logger = logging.getLogger()
- logger.addHandler(smtp_handler)
- try:
- break
- except Exception as e:
- logger.exception('Unhandled Exception')
复制代码
|
|