How do I add information to an exception message without changing its class in ruby?

Posted by Andrew Grimm on Stack Overflow See other posts from Stack Overflow or by Andrew Grimm
Published on 2010-05-13T00:36:36Z Indexed on 2010/05/13 0:44 UTC
Read the original article Hit count: 264

How do I add information to an exception message without changing its class in ruby?

The approach I'm currently using is

strings.each_with_index do |string, i|
  begin
    do_risky_operation(string)
  rescue
    raise $!.class, "Problem with string number #{i}: #{$!}"
  end
end

Is there a better way?

© Stack Overflow or respective owner

Related posts about ruby

Related posts about exception-handling