From: Sean Chittenden Date: 2001-08-27T22:11:40+09:00 Subject: [ruby-talk:20426] Re: handling errors without exiting --2mNuWrpDTYoom6W8 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable > require 'net/http' > h =3D Net::HTTP.new('test.host.it', 80) > ciao =3D Array.new > resp, data =3D h.get('/test.html', nil ) > puts "Code =3D #{resp.code}" > puts "Message =3D #{resp.message}" > resp.each {|key, val| printf "%-14s =3D %-40.40s\n", key, val } > data.each_line { |line| ciao.push($2) if /(href=3D"*(http:\/\/.*?)[>" ]){= 1,}/ =3D~ line} >=20 > begin > ciao.each {|line| > resp, data =3D h.get(line) > p line > } >=20 > rescue Net::ProtoFatalError > print "catched\n" > end Why don't you test the response before you try and read? I=20 don't think you're catching the right exception... or all of them. If=20 you get desperate: include ObjectSpace ObjectSpace.each_object(Exception) do |obj| puts obj.puts end As for your regexp, this is pulled/modified from ruby-tmpl... =20 a tad ugly, but it gets exactly what I need. Iterate over the md to see what you've caught in each paren: pattern =3D '(<[Aa].*?[Hh][Rr][Ee][Ff]\s*=3D\s*)(([\'\"])((?:[^#]).*?[^\?]*= ?){0,1}(\?.*?){0,1}\3)(.*?>)' a_tag_re =3D Regexp.new(pattern) md =3D a_tag_re.match(returned_html) i =3D 0 md.each do |m| puts i + ': ' + m i.succ! end --=20 Sean Chittenden --2mNuWrpDTYoom6W8 Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Comment: Sean Chittenden iEYEARECAAYFAjuKRwgACgkQn09c7x7d+q3/rgCfZUFQcgNgEliK6xgBpO6wJh4t vrQAn0tfVc/y8iNIN4mWYQCaRqKuw91B =gUZi -----END PGP SIGNATURE----- --2mNuWrpDTYoom6W8--