Ruby Stuff: Use retry to restart a begin rescue block

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.

4 Comments

  1. I love Ruby gyms. Begin is starting the exercise, rescue is the spotter and retry is the sets.

    In all seriousness, stumbled onto this blog looking for retries after a delay. ‘sleep’ seems to lock up the Rails process. If you nice gentleman or anyone else that stumbles onto this page has any ideas, please leave them :)

  2. Paul, Ruby is being exercised in the gym. If you put it to sleep, it will go off the Rails;-)

  3. I see a lot of interesting articles on your blog. You have to spend a lot of time writing, i know how to save you a lot of time, there is a tool that creates unique, google friendly posts in couple of seconds, just search in google – laranita’s free content source

  4. I read a lot of interesting content here. Probably you spend
    a lot of time writing, i know how to save you a lot of time, there is an online tool that creates
    high quality, SEO friendly articles in minutes, just search in google – laranitas free
    content source

Submit a Comment

Your email address will not be published. Required fields are marked *