How do I get ruby to print a full backtrace instead of a truncated one?

前端 未结 10 1584
-上瘾入骨i
-上瘾入骨i 2020-12-12 12:00

When I get exceptions, it is often from deep within the call stack. When this happens, more often than not, the actual offending line of code is hidden from me:



        
10条回答
  •  自闭症患者
    2020-12-12 12:46

    Exception#backtrace has the entire stack in it:

    def do_division_by_zero; 5 / 0; end
    begin
      do_division_by_zero
    rescue => exception
      puts exception.backtrace
      raise # always reraise
    end
    

    (Inspired by Peter Cooper's Ruby Inside blog)

提交回复
热议问题