I'm trying to figure out how to handle and exception..
I have the following code:
def whois_info
begin
Timout::timeout(5) do
File.read("urls.txt").each_line do |lookup| #file containing urls
info = system("whois #{lookup}")
File.open("whois_log.txt", "a+") {|whois| whois.puts(info)}
end
end
rescue #what I want to do is rescue exception to have it skip the line and move onto the next one.
How do I do this..?
I've tried
rescue Timeout::Error
next
But that just throws invalid next; compile error
···
Sent from my iPhone
Next can only be used inside of a loop/block. You're not because your begin/rescue is outside of all of them. Your layer logic is incorrect. Put the timeout at the right level and it'll work fine.
···
On Mar 6, 2016, at 16:17, thomas Perkins <thomas.perkins23@icloud.com> wrote:
I'm trying to figure out how to handle and exception..
I have the following code:
def whois_info
begin
Timout::timeout(5) do
File.read("urls.txt").each_line do |lookup| #file containing urls
info = system("whois #{lookup}")
File.open("whois_log.txt", "a+") {|whois| whois.puts(info)}
end
end
rescue #what I want to do is rescue exception to have it skip the line and move onto the next one.
How do I do this..?
I've tried
rescue Timeout::Error
next
But that just throws invalid next; compile error
What would the correct level look like?
···
Sent from my iPhone
On Mar 6, 2016, at 6:19 PM, Ryan Davis <ryand-ruby@zenspider.com> wrote:
On Mar 6, 2016, at 16:17, thomas Perkins <thomas.perkins23@icloud.com> wrote:
I'm trying to figure out how to handle and exception..
I have the following code:
def whois_info
begin
Timout::timeout(5) do
File.read("urls.txt").each_line do |lookup| #file containing urls
info = system("whois #{lookup}")
File.open("whois_log.txt", "a+") {|whois| whois.puts(info)}
end
end
rescue #what I want to do is rescue exception to have it skip the line and move onto the next one.
How do I do this..?
I've tried
rescue Timeout::Error
next
But that just throws invalid next; compile error
Next can only be used inside of a loop/block. You're not because your begin/rescue is outside of all of them. Your layer logic is incorrect. Put the timeout at the right level and it'll work fine.
Unsubscribe: <mailto:ruby-talk-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>
Well... what are you trying to time out? Put that inside and have everything else outside.
···
On Mar 6, 2016, at 16:26, thomas Perkins <thomas.perkins23@icloud.com> wrote:
What would the correct level look like?
So something along the lines of:
File.read("urls.txt").each_line do |lookup|
Timeout::timeout(5) do
begin
Whois lookup
save to file
rescue Timeout::Error
next
end
end
end
Does that look about right?