[Wtr-general] OT: Need help Trapping Errors in Ruby

Paul Carvalho tester.paul at gmail.com
Wed Jan 10 17:47:17 EST 2007


Got the answer I need from the Programming Ruby 2nd Edition book and thought
I would share it here.

>From the "Handling Exceptions" section (p. 361), I got that I should add the
"rescue" block to the end of my site-walking methods, and not the calling
method (i.e. page_set_to_check()).  Basically I was using the rescue block
in a way that Ruby didn't pay attention to.

So I made the following changes to my script:
(1) delete the page_set_to_check() method
(2) added the following rescue block to the end of each page set
(site-walking) method:
----
module site_walkabout_methods
  ...
  def walk_Public_Pages
      # launch ie
      # goto some page
      # get page size and download time
      # click to another page.  yadda, yadda.
      # ...
  rescue => e
      $something_went_wrong = 'Yes'
      puts e
  ensure
      write_status
  end

end
----

So the methods themselves are self-correcting and I don't need to try and
capture exceptions with some umbrella method.  Cool.

I'm happy.  Moving on..

Cheers.  Paul C.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/wtr-general/attachments/20070110/b762b19c/attachment.html 


More information about the Wtr-general mailing list