3

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?

Community
  • 1
  • 1
Virviil
  • 622
  • 5
  • 14
  • Take a look at `caller` as indicated in this other question http://stackoverflow.com/questions/6322524/how-do-you-view-a-sample-of-the-call-stack-in-ruby – Hector Correa Jan 06 '15 at 14:14

1 Answers1

4

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)

jjm
  • 6,028
  • 2
  • 24
  • 27
  • 1
    Mb, this is good solution. But why when you use some famous libraries like rack or activerecord you can see full trace of everithing? I want my library to do the same! Or, I should catch and throw again everithing and everywhere? – Virviil Jan 05 '15 at 23:30
  • I'm not 100% sure what you mean, but I think what's at issue here is that you're calling your method in irb, which suppresses some of the backtrace, whereas rack and activerecord will spit it out all over the place. – jjm Jan 06 '15 at 21:54