WikidLabs

Ruby Stuff: Use retry to restart a begin rescue block


by DL February 11th, 2010

I recently needed to be able retry a begin block and was simply nesting begins within begins, then I ran across this little Ruby gym. The retry, http://www.tutorialspoint.com/ruby/ruby_exceptions.htm.

    begin
      @calendarapi.calendars
    rescue Exception => ex
      logger.info ex
      switch_ssl()
      retry
    end

Obviously this bit of code could end in a continuous loop so be careful to add a little logic to ensure a clean exit.

Tags: ,

Be the first person to leave your comment.

Post a Comment or Question

  • You can use these HTML tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>