源代碼下載:下載地址在這裏
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
>>>