码迷,mamicode.com
首页 > 其他好文 > 详细

异常处理语法

时间:2016-09-16 15:24:40      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:

抛出异常:

try:
  print("handel")
  #raise #抛出异常

except Exception:
  print(‘error!‘)
else:
  print("no error just exec!!")
finally:
  print("aways exec!")

  print("一般用来关闭文件,sock等")

 

print("---------------")

 

断言:抛出布尔型错误。

try:
  assert 1 == 0
except AssertionError:
  print("not equal")

 

异常处理语法

标签:

原文地址:http://www.cnblogs.com/fanxuanhui/p/5876448.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!