Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby exception trace

I have Ruby function, like this:

module MyModule
  def function
    raise ArgumentException if true
  end
end

Then, I use this function in some another nesting functions just like

def upperfunction
   MyModule::function
end

So, if i call upperfunction in irb, i want to see full trace like

line 2 upperfunction.rb

line 3 my_module.rb

ArgumentError

But I get only

line 3 my_module.rb

ArgumentError

What ahould I do to see full trace?

like image 737
Virviil Avatar asked Aug 02 '26 05:08

Virviil


1 Answers

Try $@. That contains the backtrace of the last exception (the last exception object is in $!).

An alternative solution would be to use a better ruby shell, pry, in which you can see backtraces with the wtf! command (the more exclamation points, the more of the backtrace will be shown)

like image 52
jjm Avatar answered Aug 03 '26 20:08

jjm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!