1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | require 'timeout' require 'net/http' begin #raise RuntimeError timeout(0.5) do Net::HTTP.get("twitter.com", "/hyper/heavy/page", 80) end rescue => e puts "generic exception!" puts e.class, e.message rescue Timeout::Error => e puts "timeout!" puts e.class, e.message end |
コメントそのまま
timeout! Timeout::Error execution expired
コメントを外すと
generic exception! RuntimeError RuntimeError
参考
- http://www.ruby-lang.org/ja/man/html/TimeoutError.html(親クラスがInterruptな件)
- http://blog.goo.ne.jp/j_adversaria/e/0ad829ee8a1b313c73c5320987f98326




