python 处理异常问题,求解决
class ShortInputException(Exception):
'''A user-defined exception class.'''
def __init__(self,length,atleast):
Exception.__init__(self)
self.length=length
self.atleast=atleast
try:
s = 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 expecting at least %d' % (x.length, x.atleast))
else:
print('No exception was raised.')
问题:
Enter something -->
Traceback (most recent call last):
File "C:\Documents and Settings\Administrator\桌面\PYTHON\raising.py", line 15, in <module>
except ShortInputException(x):
NameError: name 'x' is not defined
'''A user-defined exception class.'''
def __init__(self,length,atleast):
Exception.__init__(self)
self.length=length
self.atleast=atleast
try:
s = 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 expecting at least %d' % (x.length, x.atleast))
else:
print('No exception was raised.')
问题:
Enter something -->
Traceback (most recent call last):
File "C:\Documents and Settings\Administrator\桌面\PYTHON\raising.py", line 15, in <module>
except ShortInputException(x):
NameError: name 'x' is not defined
...全文
相关推荐
hdu杭电所有题目按照ac数量排序,python分析
hdu杭电所有题目按照ac数量排序,python分析
Python 编码处理-str与Unicode的区别
本文主要介绍Python 编码处理的问题,这里整理了相关资料,并详细说明如何处理编码问题,有需要的小伙伴可以参考下
使用函数求特殊a串数列和
使用函数求特殊a串数列和
python except异常处理之后不退出,解决异常继续执行的实现
主要介绍了python except异常处理之后不退出,解决异常继续执行的实现,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
解决python ThreadPoolExecutor 线程池中的异常捕获问题
主要介绍了解决python ThreadPoolExecutor 线程池中的异常捕获问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧


