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 Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
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)