There are times when you want to add backtrace information or cause to an Exception instantiated on the spot. In such a case.
begin
1/0
rescue => e
err = raise RuntimeError.new, 'Let's raise any error!' rescue $!
p err
p err.cause
end
# => #<RuntimeError:Let's raise any error!>
# => #<ZeroDivisionError: divided by 0>
I think this is the fastest
Recommended Posts