Rescue + stack trace

I am working on debugging a program. I understand how to raise/rescue
exceptions, and how to capture the standard error messages as well as
provide my own.

However, I do not know how to capture the stack trace. Is there a variable
(like the $! variable for the error message), which contains a reference to
the stack trace that I would get if I were not catching these errors?
Thanks.

Matt

···

Add photos to your messages with MSN 8. Get 2 months FREE*.
http://join.msn.com/?page=features/featuredemail

However, I do not know how to capture the stack trace. Is there a variable
(like the $! variable for the error message), which contains a reference to
the stack trace that I would get if I were not catching these errors?

This ?

pigeon% ruby -e 'def a() raise "aaa"; end; a rescue p $!.backtrace'
["-e:1:in `a'", "-e:1"]
pigeon%

Guy Decoux

However, I do not know how to capture the stack trace. Is there a
variable (like the $! variable for the error message), which contains a
reference to the stack trace that I would get if I were not catching
these errors? Thanks.

I don’t know exactly how it’s called, but look in the built in classes
reference at the Exception class. It holds an array or a method which
returns an array with the stack trace…
hope this helps.

bye!
Dominik

Hi,

[dewd@localhost dewd]$ irb
irb(main):001:0> begin
irb(main):002:1* i = 10/0
irb(main):003:1> rescue => e
irb(main):004:1> puts “#{e.message}\n#{e.backtrace}”
irb(main):005:1> end
divided by 0
(irb):2:in /'(irb):2:in irb_binding’/usr/local/lib/ruby/1.8/irb/workspace.rb:52:in
`irb_binding’/usr/local/lib/ruby/1.8/irb/workspace.rb:52
=> nil

Cheers,
Joao

···

Em Qui, 2003-06-19 às 13:55, Orion Hunter escreveu:

I am working on debugging a program. I understand how to raise/rescue
exceptions, and how to capture the standard error messages as well as
provide my own.

However, I do not know how to capture the stack trace. Is there a variable
(like the $! variable for the error message), which contains a reference to
the stack trace that I would get if I were not catching these errors?
Thanks.

Matt


Add photos to your messages with MSN 8. Get 2 months FREE*.
http://join.msn.com/?page=features/featuredemail