Python异常处理(个人笔记)

Python3 异常处理

捕获全部异常

try:  
    a=b  
    b=c  
except Exception,e:  
    print Exception,":",e

各种异常清单

各种异常

抛出异常

raise NameError('HiThere')

若想知道是否抛出了异常

>>> try:
        raise NameError('HiThere')
    except NameError:
        print('An exception flew by!')
        raise
   
An exception flew by!
Traceback (most recent call last):
  File "", line 2, in ?
NameError: HiThere

你可能感兴趣的:(Python异常处理(个人笔记))