Ruby

22
1382 reads

February 27, 2013

Inheritance


Concept of inheritence

230
3352 reads

February 26, 2013

Retry 2


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

213
2928 reads

February 26, 2013

Retry


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

163
2594 reads

February 26, 2013

Raise 3


If the standard exception types don’t meet your requirements, you can, of course, create new ones just by subclassing existing exceptions.

325
3614 reads

February 26, 2013

Raise 2


You can also specifically raise your exceptions to force en error condition even when the program code itself has not caused an exception.

364
3197 reads

February 26, 2013

Raise


Sometimes you may want to keep an exception ‘alive’ even after it has been trapped in an exception-handling block.

43
1133 reads

February 26, 2013

OMITTING BEGIN AND END


You may optionally omit begin and end when trapping exceptions inside a method, a class or a module. For example Check the following Example

187
2987 reads

February 26, 2013

Multi Exception 2


Often it will be useful to take different actions for different exceptions. You can do that by adding multiple rescue clauses.

93
1229 reads

February 26, 2013

Multi Exception error


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.

250
1990 reads

February 26, 2013

Multi Exception


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.