#1.语法错误 SyntaxError
#2.异常 Exceptions
#print(8/0)
#处理单一异常
while True:
try: #将可能会出现异常的语句放到try中
x = int(input('Enter an integer:'))
break
except ValueError: #如果出现异常,将跳到except中执行
print('Not valid input, try again...')
#处理多种异常
try:
f = open('file.txt')
s = f.readline()
i = int(s.strip())
except OSError as err:
print('OS error:',err)
来源:oschina
链接:https://my.oschina.net/jugier/blog/4269288