Python:自定义异常类
来源:互联网 发布:苏曼莎捏脸数据 编辑:程序博客网 时间:2024/06/08 18:36
自定义一个异常类,判断用户输入的字符串长度是否够
#!/usr/bin/python#Filename:user_defined_exception.pyclass ShortInputException(Exception): '''A user-defined exception class.''' def __init__(self, length, atleast): Exception.__init__(self) self.length = length self.atleast = atleasttry: s = raw_input('Enter something-->') if len(s) < 3: raise ShortInputException(len(s), 3) else: print sexcept EOFError: print '\nWhy did you do an EOF on me?'#except ShortInputException, x:except ShortInputException as x: print 'ShortInputException:The input was length %d, \ was expecting at least %d.'%(x.length, x.atleast)else: print 'No exception was raised.'
0 0
- Python:自定义异常类
- Python学习--异常处理,自定义异常类
- Python 自定义异常类,主动捕获异常,主动抛出异常
- PYTHON 自定义异常类的使用
- Python自定义异常
- Python 自定义异常
- Python-自定义异常
- python 自定义异常
- Python如何自定义异常
- python自定义异常
- Python 自定义异常
- Python 用户自定义异常
- python之自定义异常
- python自定义异常
- Python学习17:异常处理(三)自定义异常类
- python 自定义异常和异常捕捉
- Python 练习代码 -- 异常,抛异常, 自定义异常
- Python 实现简单的自定义异常类型
- Telnet/SSH to Fedore Server Very Slow
- Android-基本布局
- 从编辑框获取内容
- 微软100题(88)字符串处理函数
- OC语言构造器
- Python:自定义异常类
- 第五章 作业
- 转换字符串到整数
- JAVA基础笔记——1
- Android-布局基础
- xmlbeans解析XML文件全流程+Altova XMLSpy破解
- 运用NI USRP打造出经济实惠的8x8 MIMO测试台
- MySQL v5.6.20安装配置
- msyql 统计数据,并过滤重复数据