python异常处理


python

Python3 异常处理

捕获全部异常

1
2
3
4
5
try:  
a=b
b=c
except Exception,e:
print Exception,":",e

各种异常清单

各种异常

抛出异常

1
raise NameError('HiThere')

若想知道是否抛出了异常

1
2
3
4
5
6
7
8
9
10
>>> try:
raise NameError('HiThere')
except NameError:
print('An exception flew by!')
raise

An exception flew by!
Traceback (most recent call last):
File "<stdin>", line 2, in ?
NameError: HiThere