Virviil
Virviil

Reputation: 632

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?

Upvotes: 3

Views: 323

Answers (1)

jjm
jjm

Reputation: 6178

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)

Upvotes: 4

Related Questions