From: Ryan Heneise Date: 2011-01-26T00:56:32+09:00 Subject: Re: Does Ruby support exception wrapping (exception chaining)? Robert Klemme wrote in post #977344: > DRb really seems the only place where a kind of wrapping may make > sense but even here you probably do not want to wrap exceptions but > just carry over backtraces, because the exception class may not be > known to the client. An example of where this can be infinitely useful is in parsing a CSV or Excel file, or iterating over any collection of data. Often a tuple will trigger an exception, and it's useful to know on which line the problem occurred. tuples.each_with_index do |tuple, i| begin Something.create(tuple) rescue Exception => e raise $!, "#{$!} on row #{i}", $!.backtrace end end This would give you an error like: "NoMethodError: undefined method `foobar' for nil:NilClass on row 123" ...which is very helpful when tracking down data processing errors. Notice that it still raises the original error, including the original error class, and the original backtrace. Only the message has changed. -- Posted via http://www.ruby-forum.com/.