Ruby 语法 begin rescue else end 使用 介绍
不经过else的例子
begin
1/0
rescue => e
puts "in rescue error is:#{e}"
else
puts "in else"
end
经过else的例子
begin
1/1
rescue => e
puts "in rescue error is:#{e}"
else
puts "in else"
end
也就是说,预计可能会报错,如果没有报错,就会走else的语句
使用的地方:报错和不报错 都会做某些类似事情的时候
上面的例子不是很贴切,没有体现else的用法,可以把esle去掉。
看一个ruby源码的例子:
x = Thread.current
y = Thread.start {
begin
sleep sec
rescue => e
x.raise e
else
x.raise exception, "execution expired" if x.alive?
end
}
yield sec
这里,waiting的时候,如果没有报错,也即是说没有异常的程序,表示时间到了,也要报错。
这样用的地方,就很合乎常理了。
。。。结束了。。。 END EOF
)
分享到:
相关推荐
数据包:Team_Hector_MappingBox_RoboCup_2011_Rescue_Arena.bag
A_Novel_Reconfigurable_Robot_for_Urban_Search_and_Rescue
Swarm_Robotics_Search_and_Rescuer
浙大Robocup rescue simulation
东南大学Robocup Rescue 基础源码,可以在Linux下安装Server后运行
5G_to_the_Rescue_Promise_Uncertainty
,if ,then,else,elsif,case ,when,unless,for,in,while ,until,next,break,do,redo ,retry,yield,not,and,or,true,false,nil,rescue,ensure,super,self,begin,end,BEGIN,END,__FILE...
2007年robocup rescue世界冠军源码
ruby> file = open(“some_file”) ERR: (eval):1:in `open’: No such file or directory – some_file 一个健壮的程序会合理并漂亮的处理这些问题.面对那些异常是一件讨人厌的工作.C程序员被要求...
CoppeliaSim model of ”Stability Control for End Effector of Mobile Manipulator in Uneven Terrain Based on Active Disturbance Rejection Control”
触摸屏 smart line smart 700 ie v3 smart1000 ie v3 恢复出厂 第三代精彩 面板的 USB 恢复模式
linux援救模式:linux rescue使用详细图解
华硕路由固件恢复工具Rescue_2102.zip ,这个适用于 windows 10 ,路由器固件的话需要另外下载。
我们可以在 begin/end 块中附上可能抛出异常的代码,并使用 rescue 子句告诉 Ruby 完美要处理的异常类型。 语法 begin # - rescue OneTypeOfException # - rescue AnotherTypeOfException # - else # 其他异常
redhat6.x mondo Rescue 离线包所有依赖包,直接安装使用。
(文件恢复D6代码)
东南大学robocup rescue底层代码
要捕获所有异常,请使用rescue Exception (或使用绑定名称, rescue Exception => e )。 调用超级方法可能会丢失信息 如果子类定义了一个与基类名称相同但签名不同的方法(参数较少),则调用“super”来调用基类...
Drive Rescue SOURCE CODE,一款非常厉害的文件恢复的源代码,套用了汇编。
Linux 内核崩溃 引导修复 rescue 救援笔记 vmlinuxz-2.6.32-220.el6.x86_64 initramfs-2.6.32-220.el6.x86_64.img kernel 相关文件丢失: