Concept of inheritence
There is, of course, the danger that the error may not be as transient as you think so, if you use retry, you may want to provide a clearly defined exit condition to ensure that the code stops executi
If you think an error condition may be transient or may be corrected (by the user, perhaps?), you can rerun all the code in a begin..end block using the keyword retry, as in this example which prompts
If the standard exception types don’t meet your requirements, you can, of course, create new ones just by subclassing existing exceptions.
You can also specifically raise your exceptions to force en error condition even when the program code itself has not caused an exception.
Sometimes you may want to keep an exception ‘alive’ even after it has been trapped in an exception-handling block.
You may optionally omit begin and end when trapping exceptions inside a method, a class or a module. For example Check the following Example
Often it will be useful to take different actions for different exceptions. You can do that by adding multiple rescue clauses.
When handling multiple exception types you should always put the rescue clauses dealing with specific exceptions first, then follow these with rescue clauses dealing with more generalized exceptions.
This could potentially produce a variety of different exceptions. Obviously if we divide a number entered by the user is 0, we will get a ZeroDivisionError.