Project

cause

0.09
No commit activity in last 3 years
No release in over 3 years
Allows you access to the error that was being handled when this exception was raised.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies
 Project Readme

This is a back-port of Ruby 2.1.0's Exception#cause to older versions of Ruby.

Installation

Add gem 'cause' to your Gemfile, then run bundle install. If you're not using bundler, then just gem install cause.

Usage

Just continue programming as normal. When you rescue from exceptions they'll have a third property, cause, in addition to backtrace and message. The cause is the exception object that was being handled when the error was raised.

While this is not directly useful in normal programming, it's very useful for debugging. Exception trackers like Bugsnag can then pick up the cause of the exception to help you find out what went wrong.

Limitations

At the moment you cannot set the cause yourself. Overriding raise is hairy business and I wrote this gem late at night, but with sufficient care it's probably doable.

Meta-fu

This gem is Copyright under the MIT licence. See LICENCE.MIT for details.

Contributions and bug-reports are welcome.