[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

How to print FULL stacktrace of exception w/ line #?

Andrew Chen

9/19/2007 2:28:00 AM

The ruby interpreter prints out a full trace of the exception.

However, all the expection I got is an one line message. I need to know
where the exception happened in my code. I don't mind it is verbose.

begin
....
Math.sqrt (-1)
rescue => e
puts e.inspect
end

e only prints out a message.

Am I missing anything real simple?

Thanks
~Andrew Chen
--
Posted via http://www.ruby-....

10 Answers

Konrad Meyer

9/19/2007 3:05:00 AM

0

Quoth Andrew Chen:
> The ruby interpreter prints out a full trace of the exception.
>
> However, all the expection I got is an one line message. I need to know
> where the exception happened in my code. I don't mind it is verbose.
>
> begin
> ....
> Math.sqrt (-1)
> rescue => e
> puts e.inspect
> end
>
> e only prints out a message.
>
> Am I missing anything real simple?
>
> Thanks
> ~Andrew Chen

Don't rescue it, full stack trace! :P

--
Konrad Meyer <konrad@tylerc.org> http://konrad.sobertil...

Andrew Chen

9/19/2007 3:11:00 AM

0

Konrad Meyer wrote:
>
> Don't rescue it, full stack trace! :P

In the situation, I want to rescue, and run some other logic, since I
don't want the whole class to die.
--
Posted via http://www.ruby-....

Michael Fellinger

9/19/2007 3:39:00 AM

0

On 9/19/07, Andrew Chen <meihome@gmail.com> wrote:
> The ruby interpreter prints out a full trace of the exception.
>
> However, all the expection I got is an one line message. I need to know
> where the exception happened in my code. I don't mind it is verbose.

begin
....
Math.sqrt (-1)
rescue => e
puts e.inspect
puts e.backtrace
ensure
andrew.brain << open("ri"){|ri| ri.read('Exception')}
end

Sylvain Joyeux

9/19/2007 11:39:00 AM

0

You can check utilrb's #full_message at
http://www.laas.fr/~sjoyeux/darcs/utilrb/lib/utilrb/exception/full_...

(utilrb is also available as a gem on rubyforge :))
--
Sylvain Joyeux

Sylvain Joyeux

9/19/2007 11:41:00 AM

0


> Don't rescue it, full stack trace! :P
... or not
Ruby removes in-betweeen lines if a backtrace is 'too long'. The limit is
not configurable, so it you have long backtraces (and if you need what is
in the middle) you're fucked.

--
Sylvain Joyeux

Mitch Mon

9/25/2007 6:57:00 PM

0


I miss Java.

I run into this kind of short sighted decision far too often with Ruby.
Ugh.
--
Posted via http://www.ruby-....

Alex Young

9/26/2007 7:59:00 AM

0

Sylvain Joyeux wrote:
>> Don't rescue it, full stack trace! :P
> ... or not
> Ruby removes in-betweeen lines if a backtrace is 'too long'. The limit is
> not configurable, so it you have long backtraces (and if you need what is
> in the middle) you're fucked.
>
You can get that information when you rescue the exception -
Exception#backtrace is an array of caller information.

--
Alex

Sylvain Joyeux

9/26/2007 8:17:00 AM

0

> You can get that information when you rescue the exception -
> Exception#backtrace is an array of caller information.
Yes, so I had to rescue all exceptions in all threads I spawn to have a
proper backtrace (even more so since with abort_on_exception the exception
is not shown /at all/).

Sometimes it drived me crazy ...

Sylvain Joyeux

Roger Pack

9/26/2007 3:41:00 PM

0

Sylvain Joyeux wrote:
>> You can get that information when you rescue the exception -
>> Exception#backtrace is an array of caller information.
> Yes, so I had to rescue all exceptions in all threads I spawn to have a
> proper backtrace (even more so since with abort_on_exception the
> exception
> is not shown /at all/).
>
> Sometimes it drived me crazy ...
>
> Sylvain Joyeux

You might be able to rewrite the Thread.new method and have it catch and
display exceptions (and raise them).
GL!
-Roger
--
Posted via http://www.ruby-....

Andrew Chen

9/26/2007 3:47:00 PM

0

e.backtrace works fine for me. In my case, I don't need traces in the
middle.

Thanks for all the help!

--
Posted via http://www.ruby-....