源代码下载:下载地址在这里
raise有两个参数,第一个是由我们自己定义的异常类型,第二个是关于此异常的少量说明信息。
output:
以下是两次运行的结构
>>>
Input your age:22
22
>>>
Input your age:911
Traceback (most recent call last):
File "C:/Documents and Settings/ning/桌面/Python Intro/038_RaiseAnError.py", line 11, in <module>
print getAge()
File "C:/Documents and Settings/ning/桌面/Python Intro/038_RaiseAnError.py", line 6, in getAge
raise 'BadAgeError', 'It is impossible!!!!!'
TypeError: exceptions must be classes or instances, not str
>>>