1 Star 0 Fork 0

shenjie/Python-first-Practice

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
ch14_05_try_except.py 663 Bytes
一键复制 编辑 原始数据 按行查看 历史
Fei Wan 提交于 2017-02-14 00:45 . Create ch14_05_try_except.py
class ShortInputException(Exception):
'''A user-defined exception class'''
def __init__(self, length,atleast):
Edited by LATEX80ubA Byte of Python第14章 异常
Exception.__init__(self)
self.length = length
self.atleast = atleast
try:
text = input('Enter something-->')
if len(text) < 3:
raise ShortInputException(len(text),3)
#other work can continue as usual here
except EOFError:
print('Why did you do an EOF on me')
except ShortInputException as ex:
print('ShortInputException The input was {0} long, excepted\
atleast {1}'.format(ex.length, ex.atleast))
else:
print('No exception was raised.')
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/afoye/Python-first-Practice.git
git@gitee.com:afoye/Python-first-Practice.git
afoye
Python-first-Practice
Python-first-Practice
master

搜索帮助