处理多个异常
try:
file = open('test.txt', 'rb')
except (IOError, EOFError) as e:
print("An error occurred. {}".format(e.args[-1]))try:
file = open('test.txt', 'rb')
except EOFError as e:
print("An EOF error occurred.")
raise e
except IOError as e:
print("An error occurred.")
raise etry:
file = open('test.txt', 'rb')
except Exception:
# 打印一些异常日志,如果你想要的话
raise最后更新于
这有帮助吗?