In Ruby, methods automatically define begin/end blocks. That makes it easy to write exception handlers and ensure blocks:

1 def access!(options={})
2 raise AuthorizationFailure if != options[:email]
3 self.download_count += 1
5 rescue AuthorizationFailure
6 self.unauthorized_access_count += 1
7 raise
9 ensure
11 end

It is important to re-raise the exception in the exception handler, or else the exception will be silently thrown away.


Your Host

A picture of me

I am François Beausoleil, a Ruby on Rails and Scala developer. During the day, I work on Seevibes, a platform to measure social interactions related to TV shows. At night, I am interested many things. Read my biography.

Top Tags

Books I read and recommend


Projects I work on

Projects I worked on