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 online protection

Rails professionals since 2007

Our laser focus on a single technology has made us a leader in this space. Need help?

  • We build a solid first version of your product
  • We train your development team
  • We rescue your project in trouble
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)