J
Joel VanderWerf
There are many places in my code that need to catch any error generated
by a network system call, but I don't want to catch everything that
inherits from SystemCallError. This is my current code:
ALL_NETWORK_ERRORS = [Errno::ECONNRESET, Errno::ECONNABORTED,
Errno::ECONNREFUSED, Errno::EPIPE, IOError, Errno::ETIMEDOUT]
ALL_NETWORK_ERRORS << Errno::EPROTO if defined?(Errno::EPROTO)
# this doesn't exist on mswin32
begin
raise Errno::ECONNREFUSED
rescue *ALL_NETWORK_ERRORS
puts "OK!"
end
Now, here's another option, but is there anything wrong with it?
module NetworkRaisable; end
class Errno::EPROTO; include NetworkRaisable; end
class Errno::ECONNREFUSED; include NetworkRaisable; end
# and so on
begin
raise Errno::ECONNREFUSED
rescue NetworkRaisable
puts "OK!"
end
by a network system call, but I don't want to catch everything that
inherits from SystemCallError. This is my current code:
ALL_NETWORK_ERRORS = [Errno::ECONNRESET, Errno::ECONNABORTED,
Errno::ECONNREFUSED, Errno::EPIPE, IOError, Errno::ETIMEDOUT]
ALL_NETWORK_ERRORS << Errno::EPROTO if defined?(Errno::EPROTO)
# this doesn't exist on mswin32
begin
raise Errno::ECONNREFUSED
rescue *ALL_NETWORK_ERRORS
puts "OK!"
end
Now, here's another option, but is there anything wrong with it?
module NetworkRaisable; end
class Errno::EPROTO; include NetworkRaisable; end
class Errno::ECONNREFUSED; include NetworkRaisable; end
# and so on
begin
raise Errno::ECONNREFUSED
rescue NetworkRaisable
puts "OK!"
end