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.
- 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 }
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.
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.
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.
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.
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!
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.
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.
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.
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...
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.