を上げることは、私のコードです:x
がlongInputException
さんexcept
文で使用されている理由は、ここでの例外の問題
class longInputException(Exception):
def __init__(self, length, max):
Exception.__init__(self)
self.length = len(length)
self.max = max
try:
max = 3
s = raw_input('Enter something-->')
if len(s) > max:
raise longInputException(s, max)
except longInputException, x:
print 'longInputException: the input was of length %d, \
was expecting less than or equal to %d' % (x.length, x.max)
else:
print 'No exception was raised.'
私は理解していないことです。代わりのタプルでself
を使っただけではどうですか?