Ruby Exceptions — Why “else”?

前端 未结 5 2155
长情又很酷
长情又很酷 2021-01-31 14:11

I\'m trying to understand exceptions in Ruby but I\'m a little confused. The tutorial I\'m using says that if an exception occurs that does not match any of the exceptions iden

5条回答
  •  你的背包
    2021-01-31 14:30

    The else block in a begin rescue end block is used when you are perhaps expecting an exception of some sort to occur. If you run through all of your expected exceptions but still have nothing raised, then in your else block you can do whatever's needed now that you know that your original code ran error free.

提交回复
热议问题