捕获异常
try:
觉得可能会有异常的语句
except 错误类型:
引发异常后执行的代码
except 错误类型:
pass
raise语法:
- 格式:raise 异常名称(‘异常描述’)
>>> raise Exception
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
Exception
>>>
>>> raise NameError('This is NameError')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: This is NameError
网友评论