Chinaunix首页 | 论坛 | 博客
  • 博客访问: 4447087
  • 博文数量: 1214
  • 博客积分: 13195
  • 博客等级: 上将
  • 技术积分: 9105
  • 用 户 组: 普通用户
  • 注册时间: 2007-01-19 14:41
个人简介

C++,python,热爱算法和机器学习

文章分类

全部博文(1214)

文章存档

2021年(13)

2020年(49)

2019年(14)

2018年(27)

2017年(69)

2016年(100)

2015年(106)

2014年(240)

2013年(5)

2012年(193)

2011年(155)

2010年(93)

2009年(62)

2008年(51)

2007年(37)

分类: Python/Ruby

2014-12-27 23:02:21

原文地址:http://stackoverflow.com/questions/2191632/begin-rescue-and-ensure-in-ruby
Yes, ensure ensures that the code is always evaluated. That's why it's called ensure. So, it is equivalent to Java's and C#'s finally.
The general flow of begin/rescue/else/ensure/end looks like this:
点击(此处)折叠或打开
  1. begin
  2.   # something which might raise an exception
  3. rescue SomeExceptionClass => some_variable
  4.   # code that deals with some exception
  5. rescue SomeOtherException => some_other_variable
  6.   # code that deals with some other exception
  7. else
  8.   # code that runs only if *no* exception was raised
  9. ensure
  10.   # ensure that this code always runs, no matter what
  11. end


阅读(1211) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~