Jump to ratings and reviews
Rate this book

Exceptional Ruby: Master the Art of Handling Failure in Ruby

Rate this book
Writing code that works is hard. Writing code that handles unexpected errors and still works is really hard. Most of us learn by trial and error. This short book removes the uncertainty. With over 100 pages of content and dozens of working examples, you’ll learn everything from the mechanics of how exceptions work to how to design a robust failure management architecture for your app or library. Whether you are a Ruby novice or a seasoned veteran, Exceptional Ruby will help you write cleaner, more resilient Ruby code.

102 pages, ebook

First published May 1, 2011

11 people are currently reading
323 people want to read

About the author

Avdi Grimm

4 books254 followers

Ratings & Reviews

What do you think?
Rate this book

Friends & Following

Create a free account to discover what your friends think of this book!

Community Reviews

5 stars
58 (26%)
4 stars
108 (49%)
3 stars
48 (22%)
2 stars
2 (<1%)
1 star
1 (<1%)
Displaying 1 - 17 of 17 reviews
6 reviews3 followers
November 22, 2012
Great book!

Here are my quizz notes:

- What is the diff bt raise and fail?
=> no diff

- Are raise//fail ruby keywords or methods?
=> Kernel#raise (are methods)

- Re-raise last exception
=>
# With no arguments will re-raise exception in $! If nil then RuntimeError
# note $! value is nil initialized as soon as the begin..rescue.end block terminates
raise

- What is the third argument of raise and give an example of what to put there.
=> the backtrace, use for example Kernel#caller

- What is catch/throw used for?
=> not related to exceptions, catch/throw allows you
to quickly exit blocks back to a point where a catch is defined for a specific symbol

- Diffs bt `redo` vs `retry`
=> Both ruby keywords are used to re-execute parts of a loop but:
redo only repeats the current iteration
retry repeats the whole loop from the start in 1.8 but in 1.9 gives SyntaxError: Invalid retry
Note retry should only be used inside immediate rescue blocks

- What can you use to ignore/continue/retry//etc on every ruby program error, console based?
=> the `hammertime` gem. just require 'hammertime'

- Test unit, describe the test helpers (assertions) for
equality, check nothing raised, check something raised.
=>
assert_equal val1, val2
assert_nothing_raised { block }
# ensure some exception is not raised
assert_nothing_raised ArgumentError { block }
# ensure something is raised
assert_raise { block }
# ensure some exception is raised
assert_raise NameError { puts asd }

Profile Image for Nitish Parkar.
45 reviews1 follower
December 20, 2020
This book is a deep dive into Ruby exceptions. It starts with the explanation of Ruby exceptions and exception handling mechanisms and goes on suggesting some techniques to deal with them effectively. There is very little overlap with Confident Ruby. Even though this book covers a small part of the language, it is full of practical insights. I would recommend this to anyone looking to improve their Ruby skills.
Profile Image for Oleksandr .
280 reviews7 followers
November 28, 2016
I learnt several Ruby specific things from the book:
- fail is just alias for raise
- use raise as default value when key is expected
- it is possible to include module in error and then rescue by module.
There were some general things, but they better covered in referenced books.
9 reviews
May 5, 2017
It's a good book. It is easy to read and Avdi explain ruby exceptions in depth. I've learned a lot about it and there are many things I didn't know exists.

I've missed an good index for the pratices shown in the book, like a resume of the patterns presented with code samples.
Profile Image for Dim Ether.
14 reviews5 followers
August 19, 2017
A few bright moments, some neat tricks; good enough for a lengthy blog post. I've expected either a bit more depth or better tips for error handling beyond common sense, maybe even both.
Profile Image for Michael.
163 reviews74 followers
June 18, 2012
If you are a long term Rubyist, you probably know Avdi Grim and his writings. This little book covers a topic that lots of programming books just gloss over or skip altogether, exceptions. It's a thorough wrap-up of everything Rubyists should know about exceptions and even mentioned a couple of things that got me thinking about the way I deal with exceptions in Ruby, and that's after 8 or 9 years of using the language. Definitely recommended!
Profile Image for Katherine.
883 reviews44 followers
June 18, 2015
Worth reading and interesting stuff in here. I had been expecting more of what was in the last section, which is higher-level exception handling strategy, vs a lot of detail into all the weird things you could do to mess with how Ruby exception throwing works--interesting to learn, but not as directly useful imo.
4 reviews
January 16, 2016
Rather than a deep dive under the hood of Ruby's exceptions, I was hoping for more of a surface-level, practical guide to how and when to use exceptions in Ruby - especially in Rails apps. It does cover that side a bit, but only at the end. For me, most of the content in the book was interesting but esoteric stuff that I'll likely forget, and never need to apply in real live.
48 reviews2 followers
December 11, 2012
After reading this book, it became apparent to me how under-appreciated the discussion of exception and error handling is in the programming literature. This book is definitely worth reading.. and rereading. It is short and to the point, describes practical techniques which can be simply applied.
Profile Image for Orban.
41 reviews
March 28, 2014
I recommend reading this book. It shows plenty of techniques how to handle deal with failures and errors. My favorite was when it showed how to 'tag' an exception like IOException to be able to caught as OurLibrary:OurException. :) + Many More...
1 review
April 16, 2012
Fun to read. Shows you how to think of a more rubyish way of handeling errors.
Profile Image for Alpha.
449 reviews10 followers
April 18, 2012
A nice, succinct read on exception handling in Ruby. I learned some good stuff here, especially guidance on when exceptions should be used.
8 reviews
November 29, 2014
This book brings a whole new meaning to handling exceptions. There are many things you will learn from this book, even if you are a seasoned Ruby developer.
Displaying 1 - 17 of 17 reviews

Can't find what you're looking for?

Get help and learn more about the design.