1

当您尝试在绑定语句中两次使用相同的地址时,我试图挽救 ruby​​ 引发的异常。该文档不是很有帮助。
这就是我想要的:

require 'socket'
s = UDPSocket.new(Socket::AF_INET)
begin
  s.bind address,port
rescue #Address_in_use => e
  #code
end
4

1 回答 1

2

rescue没有明确的 Exception 类只能拯救StandardError及其子类。您应该执行以下操作:

rescue Errno::EADDRINUSE => ex
  #code
end
于 2013-11-18T09:23:58.177 回答