99999久久久久久亚洲,欧美人与禽猛交狂配,高清日韩av在线影院,一个人在线高清免费观看,啦啦啦在线视频免费观看www

熱線電話:13121318867

登錄
2018-10-23 閱讀量: 1108
python錯(cuò)誤解析(五)

代碼如下:

bad = 'bad'  

try:
raise bad
except bad:
print 'Got Bad!'

錯(cuò)誤:

Traceback (most recent call last):  
File "D:\Learn\Python\Learn.py", line 4, in <module>
raise bad
TypeError: exceptions must be old-style classes or derived from BaseException, not str

【錯(cuò)誤分析】因所用的Python版本2.7,比較高的版本,raise觸發(fā)的異常,只能是自定義類異常,而不能是字符串。所以會(huì)報(bào)錯(cuò),字符串改為自定義類,就可以了。

代碼如下:

class Bad(Exception):  
pass

def raiseException():
raise Bad()

try:
raiseException()
except Bad:
print 'Got Bad!'
0.0000
5
關(guān)注作者
收藏
評(píng)論(0)

發(fā)表評(píng)論

暫無數(shù)據(jù)
推薦帖子