首页 > 代码库 > 异常链

异常链

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]

异常链