[ruby-talk:00207] Re: Rescuing from a ^C?

From: Kazuhiro HIWADA <hiwada@...>
Date: 1999-01-22 12:47:56 UTC
List: ruby-talk #207
Hi,

From: Julian Fondren <julian@imaji.net>
Subject: [ruby-talk:00206] Rescuing from a ^C?

> How would I in ruby rescue from a ^C? rescue with no arguments, Interrupt,
> or SystemExit fail, as does ensure. What I would like to do is allow ^C to
> escape from a loop, and then to continue the program.

You can trap SIGINT like this,

begin
  trap("INT"){ raise }
  while true
  end
rescue
  print "rescue!\n"
  trap("INT", "DEFAULT")
end

Hope this helps..
--
Kazuhiro HIWADA

In This Thread