摘要: 这个版本应该是比较舒服的。。案例那个有点头疼。。#!/usr/bin/pythonclass ShortInputException(Exception): def __init__(self,length,altease): Exception.__init__(self) self.length=length self.altease=alteasetry: s=raw_input('Enter->:') if len(s) < 3: raise ShortInputException(len(s),3)except... 阅读全文
posted @ 2013-03-07 23:53 墨迹哥's 阅读(222) 评论(0) 推荐(0) 编辑
摘要: 这个自定义异常的案例里面,有个关键字没有做解释。果断GOOGLE一下,raise的意思是抛出指定的异常。其他的倒没什么,不过这种指定异常应该挺特殊的,但是没有想到该在什么场景使用。。#!/usr/bin/python#coding=gbk#自定义一个异常class ShortInputException(Exception): def __init__(self,length,atleast): Exception.__init__(self) self.length=length self.atleast=atleasttry: #这里主... 阅读全文
posted @ 2013-03-07 13:57 墨迹哥's 阅读(448) 评论(0) 推荐(0) 编辑
摘要: try-except 可以应用所有错误,同时也可以指定错误的类型进行过滤。除非特殊需求,对于我来说就不需要特定的了。。。#!/usr/bin/pythonimport systry: s=raw_input('Enter:')except: sys.exit()下面这个案例是简明教程的,但是一般来说,上面的够用了。特定的错误有的时候无法估计,除非你很懂。。 #!/usr/bin/python# Filename: try_except.pyimport systry: s = raw_input('Enter something --> ')except 阅读全文
posted @ 2013-03-07 12:18 墨迹哥's 阅读(191) 评论(0) 推荐(0) 编辑