📄 raising.py
字号:
#!/usr/bin/python
# -*- coding: cp936 -*-
#fielname:raising.py
class ShortInputException(Exception):
'''自己定义的输入字符串太短的异常类
抛出ShortInputException异常'''
def __init__(self,length,atleast):
Exception.__init__(self)
self.length=length
self.atleast=atleast
try:
s=raw_input("请你输入一个字符串")
if len(s)<3:
raise ShortInputException(len(s),3)
except ShortInputException,x:
print "你输入的字符串太短,你的输入是%d,期望得到%d"%(x.length,x.atleast)
else:
print"没有异常发生"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -