A case to handle if there are no exceptions?
Ruby allows default case handling only if there is no exception with else
!
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.
The else
is only allowed if there are rescue
and can therefore be used wherever rescue
can be used: block, method and even class!
Link to Ruby documentation for exception handling
.