public Method

Exception.backtrace

exception.backtrace     array

Returns any backtrace associated with the exception. The backtrace is an array of strings, each containing either ``filename:lineNo: in `method’’’ or ``filename:lineNo.’‘

def a
  raise "boom"
end

def b
  a()
end

begin
  b()
rescue => detail
  print detail.backtrace.join("\n")
end

produces:

prog.rb:2:in `a'
prog.rb:6:in `b'
prog.rb:10

Source Code

/*
*  call-seq:
*     exception.backtrace    => array
*  
*  Returns any backtrace associated with the exception. The backtrace
*  is an array of strings, each containing either ``filename:lineNo: in
*  `method''' or ``filename:lineNo.''
*     
*     def a
*       raise "boom"
*     end
*     
*     def b
*       a()
*     end
*     
*     begin
*       b()
*     rescue => detail
*       print detail.backtrace.join("\n")
*     end
*     
*  <em>produces:</em>
*     
*     prog.rb:2:in `a'
*     prog.rb:6:in `b'
*     prog.rb:10
*/

static VALUE
exc_backtrace(exc)
   VALUE exc;
{
   static ID bt;

   if (!bt) bt = rb_intern("bt");
   return rb_attr_get(exc, bt);
}
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.