To you who absolutely need backtrace

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

To you who absolutely need backtrace
Do you need dotenv-rails?
To you who lament that Java's main method is static
To you who suffer from unexpected decimal points in Java
[IOS] What you need to know before creating a widget
Rails: You need to supply at least one validation error
[Organization] To you who get messed up with render & redirect_to
Akanechan who listens to anything
Until you push to Github