Things I Felt Like Posting

Error Handling in Ruby

I've recently begun learning Ruby by working my way through the Ruby Koans. I finally made it to the section on error handling, which answered a few questions for me.

Once again, Ruby has not surprised me (this is a good thing). There's just some minor syntactical differences. Specifically in place of "try, catch, finally" Ruby uses "begin, rescue, ensure".

  fail "Oops"
rescue StandardError => ex
  #Do something with the error
  result = :code_that_always_runs

Since I haven't made it all the way through the koans yet I'm, probably missing something that seems obvious to long time Ruby users, but so far it's pretty damned simple.

Comments (1) -

  • stever b

    11/13/2009 2:38:47 PM |

    And to think, it only took me nine months to write those few paragraphs!

Comments are closed