Python Errors and Exceptions

1. python中的try{}catch{}

2. raise exception

3. try...except ... else.. 

4. finally块 

python中的异常处理的keyword和c#中的是不同样的,python中使用try,except关键在来处理异常,例如以下:


 

2. raise excepption

python中假设在except中假设须要将异常又一次抛出能够使用keywordraise,类似于c#中的throwkeyword。

 

It is useful for code that must be executed if the try clause does not raise an exception

else块是说假设异常没有被抛出的情况下将被运行。

 

A finally clauseis always executed before leaving thetrystatement

finally块是一定会被运行的,不论异常是否产生。

具体页面:http://www.verydemo.com/demo_c122_i12332.html

posted @ 2014-10-19 10:35  yxwkaifa  阅读(180)  评论(0编辑  收藏  举报