捕获异常的两种方式 方法一 #coding=utf-8 import sys try: with open("ddd.txt", "r") as f: data = f.read() print data except: err = sys.exc_info() print err sys.exc_info()返回三元组,分别是,异常类型、异常值、异常追溯地址 方法二 #coding=utf-8 try: with open("ddd.txt", "r") as f: data = f.read() print data except Exception as e: print str(e)
原文地址:https://www.cnblogs.com/themost/p/9261531.html
时间: 2024-10-19 06:34:09