3.3 异常
>>> raise Exception('An error occurred')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
Exception: an error occurredtry:
<try suite>
except <exception class> as <name>:
<except suite>
...>>> try:
x = 1/0
except ZeroDivisionError as e:
print('handling a', type(e))
x = 0
handling a <class 'ZeroDivisionError'>
>>> x
03.3.1 异常对象
Last updated