首页 > 编程语言 > 详细

Python handling an exception

时间:2017-01-17 21:25:55      阅读:284      评论:0      收藏:0      [点我收藏+]
#try...except...
try:
   You do your operations here;
   ......................
except ExceptionI:
   If there is ExceptionI, then execute this block.
except ExceptionII:
   If there is ExceptionII, then execute this block.
   ......................
else:
   If there is no exception then execute this block. 

#The except Clause with No Exceptions
try:
   You do your operations here;
   ......................
except:
   If there is any exception, then execute this block.
   ......................
else:
   If there is no exception then execute this block. 

#The except Clause with Multiple Exceptions
try:
   You do your operations here;
   ......................
except(Exception1[, Exception2[,...ExceptionN]]]):
   If there is any exception from the given exception list, 
   then execute this block.
   ......................
else:
   If there is no exception then execute this block. 

#The try-finally Clause
try:
   You do your operations here;
   ......................
   Due to any exception, this may be skipped.
finally:
   This would always be executed.
   ......................

#Argument of an Exception
try:
   You do your operations here;
   ......................
except ExceptionType, Argument:
   You can print value of Argument here...

  

Python handling an exception

原文:http://www.cnblogs.com/KennyRom/p/6294536.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!