![]() |
#2
为Jay沉沦2012-04-13 20:01
|

class ShortInputException(Exception):
'''a user-defined exception class.'''
def __int__(self,length,atleast):
Exception.__int__(self)
self.length=length
self.atleast=atleast
try:
s=raw_input('enter something-->')
if len(s)<3:
raise ShortInputException(len(s),3)
except EOFError:
print '\nwhy did you do an EOF on me?'
except ShortInputException,x:
print 'ShortInputException:The input was of length %d,\
was expectiing at least %d' %(x.length,x.atleast)
else:
print 'no exception was raised.'
代码中的except ShortInputException,x:其中x前面的都好代表什么意思。 '''a user-defined exception class.'''
def __int__(self,length,atleast):
Exception.__int__(self)
self.length=length
self.atleast=atleast
try:
s=raw_input('enter something-->')
if len(s)<3:
raise ShortInputException(len(s),3)
except EOFError:
print '\nwhy did you do an EOF on me?'
except ShortInputException,x:
print 'ShortInputException:The input was of length %d,\
was expectiing at least %d' %(x.length,x.atleast)
else:
print 'no exception was raised.'