Read more

skorks/nesty

Henning Koch
April 08, 2015Software engineer at makandra GmbH

When raising a new exception in a rescue block, Ruby 2.1+ automatically remembers the original exception as Exception#cause.

Nested exceptions for Ruby:

When you rescue an error and then re-raise your own, you don't have to lose track of what actually occured, you can keep/nest the old error in your own and the stacktrace will reflect the cause of the original error.

Illustration UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
Read more Show archive.org snapshot

This is awesome when you classes convert exception classes. I now always subclass Nesty::NestedStandardError instead of StandardError for my own error classes.

About Exception#cause

Ruby 2.1 has a built-in mechanism with Exception#cause, which serves a similiar purpose as Nesty. However, any code printing your stack trace (Exception Notifier, Airbrake, Sentry, your IRB shell, etc.) needs to be aware of Exception#cause. Nesty on the other hand-merges the stack trace array of the current and previous exception.

This way Nesty does not need to rely on other tools to display Exception#cause.

There is also a backport of Exception#cause for older Rubies Show archive.org snapshot .

Posted by Henning Koch to makandra dev (2015-04-08 08:38)