Nestegg

Get Version

0.0.2

→ ‘nestegg’

What

Nestegg provides a nested exception facility for Ruby.

Installing

sudo gem install nestegg

The basics

Sometimes exceptions cause other exceptions. Nestegg aims to make it easier to raise exceptions with useful contextual information without loss of detail about the underlying exception.

Demonstration of usage

require 'rubygems'
require 'nestegg'

class ConfigurationError < StandardError
  include Nestegg::NestingException
end

def read_config_file
  File.open('missing_config_file') do |f|
    f.readlines
  end
end

def load_config
  begin
    lines = read_config_file
    # ... then use it to do stuff 
    # ... stuff that might fail for other reasons
  rescue
    raise ConfigurationError
  end
end

load_config

outputs

nestegg_example.rb:20:in `load_config': ConfigurationError (ConfigurationError)
        from cause: Errno::ENOENT: No such file or directory - missing_config_file
        from nestegg_example.rb:9:in `initialize'
        from nestegg_example.rb:9:in `open'
        from nestegg_example.rb:9:in `read_config_file'
        from nestegg_example.rb:16:in `load_config'
        from nestegg_example.rb:24

Code

The trunk repository is svn://rubyforge.org/var/svn/nestegg/trunk for anonymous access.

License

This code is free to use under the terms of the MIT license.

Contact

Comments are welcome. Contact me via my blog or on the nestegg-users email list.

Nestegg was created by John D. Hume.

Last modified 28th June 2007
This website generated by the New Gem Generator by Dr Nic
Theme extended from Paul Battley