Skip to Content
Effective Ruby: 48 Specific Ways to Write Better Ruby
book

Effective Ruby: 48 Specific Ways to Write Better Ruby

by Peter Jones
September 2014
Intermediate to advanced content levelIntermediate to advanced
240 pages
7h 2m
English
Addison-Wesley Professional
Content preview from Effective Ruby: 48 Specific Ways to Write Better Ruby

4. Exceptions

Sometimes an error condition is bad enough that it seems flat-out rude to return nil from a method. When things get this mucked up it’s best to unwind the stack and provide details describing the failure.

Purists (of which I’m a card-carrying member) believe that exceptions should rarely be used...mostly to give a meaningful apology to the user (followed promptly by crashing the program and discarding all her hard work).

Ruby programmers tend to be more liberal with exceptions. A number of routine error conditions are encoded into standard exception classes and used to report specific failures. Fortunately, the most common exception classes contain enough information that it’s practical to rescue the exception and recover from the ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

The Ruby Way: Solutions and Techniques in Ruby Programming, Third Edition

The Ruby Way: Solutions and Techniques in Ruby Programming, Third Edition

Hal Fulton, André Arko
Ruby Cookbook, 2nd Edition

Ruby Cookbook, 2nd Edition

Lucas Carlson, Leonard Richardson

Publisher Resources

ISBN: 9780133847086Purchase book