您的位置:首页 > 编程语言 > Python开发

Python 简单异常处理

2014-10-17 00:00 423 查看
s=raw_input("Input your age:")
if s =="":
raise Exception("Input must no be empty.")

try:
i=int(s)
except ValueError:
print "Could not convert data to an integer."
except:
print "Unknown exception!"
else: # It is useful for code that must be executed if the try clause does not raise an exception
print "You are %d" % i," years old"
finally: # Clean up action
print "Goodbye!"
raw_input("press any key to continue...")
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  python