[原]Python 简单异常处理

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...")

作者:svitter 发表于2014-5-2 23:28:04 原文链接
阅读:14 评论:0 查看评论
posted @ 2014-05-02 23:28  svtter  阅读(168)  评论(0编辑  收藏  举报