码迷,mamicode.com
首页 > 其他好文 > 详细

异常链

时间:2014-12-23 13:41:13      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:

class InvalidDataError(Exception):pass

def process(data):
try:
i=int(data)
except ValueError as err:
raise InvalidDataError(‘Invalid data received‘) from err    #from err

process(‘17.5‘)

 

-------------------------------------------------------------------

Traceback (most recent call last):
File "D:\A\com\joker.py", line 107, in process
i=int(data)
ValueError: invalid literal for int() with base 10: ‘17.5‘

The above exception was the direct cause of the following exception:   #重点

Traceback (most recent call last):
File "D:\A\com\joker.py", line 111, in <module>
process(‘17.5‘)
File "D:\A\com\joker.py", line 109, in process
raise InvalidDataError(‘Invalid data received‘) from err
__main__.InvalidDataError: Invalid data received
[Finished in 0.2s with exit code 1]

异常链

标签:

原文地址:http://www.cnblogs.com/Citizen/p/4179811.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!