Python 自定义异常练习

这个版本应该是比较舒服的。。案例那个有点头疼。。

#!/usr/bin/python

class ShortInputException(Exception):
    def __init__(self,length,altease):
        Exception.__init__(self)
        self.length=length
        self.altease=altease

try:
    s=raw_input('Enter->:')
    if len(s) < 3:
        raise ShortInputException(len(s),3)
except ShortInputException,x:
    print 'The Error:length < %d task: %d' % (x.length,x.altease)
except:
    print 'No error'
原文地址:https://www.cnblogs.com/xiaoCon/p/2949086.html