0045 Rescue_else

A case to handle if there are no exceptions?

Ruby allows default case handling only if there is no exception with else!

0045-rescue_else_1.png

What’s the point, given that the code could have been placed in the begin? Well, the code in the else is no longer protected by the rescue. This means you don’t have to deal with an unexpected exception as a side-effect.

0045-rescue_else_2.png

The else is only allowed if there are rescue and can therefore be used wherever rescue can be used: block, method and even class!

0045-rescue_else_3.png

Link to Ruby documentation for exception handling.