Main Page | Report this Page
Computers Forum Index  »  Computer Languages (Ruby)  »  Having issues with exception...
Page 1 of 1    

Having issues with exception...

Author Message
Kyle Johnson...
Posted: Thu Oct 29, 2009 5:18 am
Guest
Hi, I have been having a bit of an issue. I am trying to create a
program that will allow me to run a file containing a directory listing
line by line through a proxy. I am designing this to help with my job, I
am a web application pen tester. The only issue with the code is I am
running into 404 and 502 errors which is to be expected. I would like to
find a way to handle the exception without bringing the execution to a
halt or deleting anything from the original directory listing. Here is
my code

begin
list = IO.foreach(url_file) {|line| agent.get(line)}
rescue WWW::Mechanize::ResponseCodeError
puts "Page not found"
end

Please if anyone has an idea on how to make this work I would very much
appreciate the help.
--
Posted via http://www.ruby-forum.com/.
 
Marnen Laibow-Koser...
Posted: Fri Oct 30, 2009 3:09 am
Guest
Judson Lester wrote:
Quote:
From the OPs description of the problem, and the code presented, yes,
the
rescue will catch the exception, but that will stop the loop.

So, if you're trying to get /missing.html, /broken.html,
/the_url_I_want.svg, and missing raises a 404, then that will get caught
by
the rescue outside of the loop, and you won't make further requests. In
other words:

input:
http://site.com/missing.html
http://site.com/aweseom.html

output:
Page Not Found

When what I understood Kyle to want from the output is something like
Page Not Found
"It's spelled 'awesome'"

I think you're right about what the OP wants. I had initially thought
that both syntaxes would stop the loop, but on second reading, I think I
was wrong about that. Gotcha.

Quote:

Judson

Best,
--
Marnen Laibow-Koser
http://www.marnen.org
marnen at (no spam) marnen.org
--
Posted via http://www.ruby-forum.com/.
 
Kyle Johnson...
Posted: Fri Oct 30, 2009 5:17 am
Guest
Thank you so much guys. IT WORKS!!!! We have seriously been beating our
heads over our desks about this. I really appreciate it guys. Do you
guys have twitter at all? I would like to give you some credit for this.
--
Posted via http://www.ruby-forum.com/.
 
 
Page 1 of 1    
All times are GMT
The time now is Tue Dec 08, 2009 1:04 pm