World of program crashes with errors, Rescue it! — Ruby World

What you prefer when it comes to rescue? Rescue the specific exception, not every exception!

There are two scenarios:

1. Where you know what type of error can be thrown by a piece of code that you write.

2. When you cannot say the type of error OR a class of that error OR the situation is unknown for instance, network timeout. Also, it applies when you’re not raising any error specifically, but still wants to rescue the exception because you know that code might throw errors.

The Default is StandardError

Choose it in the second scenario. By default, rescue only catches things that are StandardError That means when you don’t pass any class Ruby considers it as a StandardError. — It’s a default.

Rescuing Specific Errors/Exceptions

Choose it when you know the specific error type and Exception class to rescue it. Find out the exception class hierarchy from here!

Rescue with specific exception class is always a better choice and a better approach to protect/save your Ruby world!

Happy Coding!! — Rubyist