当前位置: 首页>>编程示例 >>用法及示例精选 >>正文


Ruby Interrupt类用法及代码示例

本文简要介绍ruby语言中 Interrupt类 的用法。

在收到中断信号时引发,通常是因为用户按下了Control-C(在大多数 posix 平台上)。因此,它是 SignalException 的子类。

begin
  puts "Press ctrl-C when you get bored"
  loop {}
rescue Interrupt => e
  puts "Note: You will typically use Signal.trap instead."
end

产生:

Press ctrl-C when you get bored

then waits until it is interrupted with Control-C and then prints:

Note: You will typically use Signal.trap instead.

相关用法


注:本文由纯净天空筛选整理自ruby-lang.org大神的英文原创作品 Interrupt类。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。