There is actually a library implementing this kind of exception
handling. I haven't used it personally but looks OK. In one of my
projects where I needed causes on exceptions I made it "manual" way.

https://github.com/loganb/nestegg

I think that causes in exceptions do you no harm except longer stack
messages. Having them in place changes one more thing there when
catching exception and throwing new to have some additional information
one is not obligated to think "what information I'm loosing here". This
adds some DRY to the code so I like it.

Cheers
Avdi Grimm wrote in post #982947:
> On Mon, Feb 21, 2011 at 4:31 AM, Robert Klemme > Is it really that
> common? It may seem so on first sight but I can't
>> remember having ever felt the need for this in Ruby. This may have to
>> do with my usage patterns of the language but I feel that you usually
>> deal with exceptions only by either logging the message or rolling
>> back some other code's work.
>
> Libraries which throw away the original exception and substitute their
> own have caused me no end of grief. I recommend introducing an
> "original" attribute in library exception classes which can be used to
> point to the original exception that was replaced. It is even possible
> to automatically populate this attribute:
>
>   class MyError < StandardError
>     attr_reader :original
>     def initialize(msg, original=$!)
>       super(msg)
>       @original = original;
>     end
>   end
>
> Cheers,

-- 
Posted via http://www.ruby-forum.com/.