[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Backtrace without skips needed

Tobias Peters

11/26/2003 8:26:00 AM

Is there a way to tell ruby that it must never skip levels in the
backtrace like this:

/lib/ruby/1.8/net/ftp.rb:192:in `readline': End of file reached (EOFError)
from /lib/ruby/1.8/net/ftp.rb:192:in `getline'
from /lib/ruby/1.8/net/ftp.rb:202:in `getmultiline'
from /lib/ruby/1.8/net/ftp.rb:216:in `getresp'
from /lib/ruby/1.8/net/ftp.rb:232:in `voidresp'
from /lib/ruby/1.8/net/ftp.rb:157:in `connect'
from /lib/ruby/1.8/net/ftp.rb:155:in `synchronize'
from /lib/ruby/1.8/net/ftp.rb:158:in `connect'
from /lib/ruby/1.8/net/ftp.rb:119:in `initialize'
... 7 levels...
from getp.rb:85:in `get_from'
from getp.rb:85:in `open'
from getp.rb:85:in `get_from'
from getp.rb:120

This is the backtrace the ruby interpreter prints out when it terminates
due to an unhandled exception.

Thanks,
Tobias

9 Answers

matz

11/26/2003 12:04:00 PM

0

Hi,

In message "Backtrace without skips needed"
on 03/11/26, Tobias Peters <tpeters@invalid.uni-oldenburg.de> writes:

|Is there a way to tell ruby that it must never skip levels in the
|backtrace like this:

begin
foo
rescue => e
cb = e.backtrace
print cb.shift, ":", e.message, "\n"
cb.each{|c| print "\tfrom ", c, "\n"}
exit 1
end

matz.


Hugh Sasse

11/26/2003 2:11:00 PM

0

zoranlazarevic

11/26/2003 2:32:00 PM

0

> Is there a way to tell ruby that it must never skip levels in the

You might want to enclose your 'main' into begin/rescue/end and print
the stacktrace for yourself

begin
main # main raises an exception, e.g. 1/0
rescue
caller.each{|x| p x}
end

Tobias Peters

11/26/2003 2:36:00 PM

0

Thank you for your replies.

What I was really hoping for a is a command line switch to the ruby
interpreter, i.e. something that I do not need to modify my source for.

Maybe I can require some file on the command line with
-r complete_backtrace that implements $!.backtrace printing
in an atexit handler? Otherwise, I plan to modify my ruby interpreter to
make the maximum number of stack frames printed configurable via
environment variable.

Will post when I have something.

Tobias


Robert Klemme

11/26/2003 2:52:00 PM

0


"Zoran Lazarevic" <zoranlazarevic@yahoo.com> schrieb im Newsbeitrag
news:32c0bb6a.0311260632.1f53c93e@posting.google.com...
> > Is there a way to tell ruby that it must never skip levels in the
>
> You might want to enclose your 'main' into begin/rescue/end and print
> the stacktrace for yourself
>
> begin
> main # main raises an exception, e.g. 1/0
> rescue
> caller.each{|x| p x}
> end

I'm afraid, that won't output the interesting part, namely the stack
levels *below* this method that make it possible to find the source of the
exception.

Regards

robert

Robert Klemme

11/26/2003 5:00:00 PM

0


"Tobias Peters" <tpeters@invalid.uni-oldenburg.de> schrieb im Newsbeitrag
news:bq2i45$dcb$1@newssrv2.hrz.uni-oldenburg.de...
> Thank you for your replies.
>
> What I was really hoping for a is a command line switch to the ruby
> interpreter, i.e. something that I do not need to modify my source for.
>
> Maybe I can require some file on the command line with
> -r complete_backtrace that implements $!.backtrace printing
> in an atexit handler? Otherwise, I plan to modify my ruby interpreter to
> make the maximum number of stack frames printed configurable via
> environment variable.

Before you start, maybe Matz could commment on the idea of having a
~/.rubyrc that controls interpreter bahavior (of course together with a
switch that allows for ignoring this file). Then maybe he / we / you
implement this feature for the complete runtime and all / several command
line switches.

Kind regards

robert

matz

11/26/2003 11:13:00 PM

0

Hi,

In message "Re: Backtrace without skips needed"
on 03/11/27, "Robert Klemme" <bob.news@gmx.net> writes:

|Before you start, maybe Matz could commment on the idea of having a
|~/.rubyrc that controls interpreter bahavior (of course together with a
|switch that allows for ignoring this file). Then maybe he / we / you
|implement this feature for the complete runtime and all / several command
|line switches.

I'd say "no" to the rc idea. I believe it's application matter, not
language matter, i.e. there can be no common configuration among all
applications written in Ruby.

matz.

Gavin Sinclair

11/27/2003 6:24:00 AM

0

On Wednesday, November 26, 2003, 7:47:10 PM, Tobias wrote:

> Is there a way to tell ruby that it must never skip levels in the
> backtrace like this:

> /lib/ruby/1.8/net/ftp.rb:192:in `readline': End of file reached (EOFError)
> from /lib/ruby/1.8/net/ftp.rb:192:in `getline'
> from /lib/ruby/1.8/net/ftp.rb:202:in `getmultiline'
> from /lib/ruby/1.8/net/ftp.rb:216:in `getresp'
> from /lib/ruby/1.8/net/ftp.rb:232:in `voidresp'
> from /lib/ruby/1.8/net/ftp.rb:157:in `connect'
> from /lib/ruby/1.8/net/ftp.rb:155:in `synchronize'
> from /lib/ruby/1.8/net/ftp.rb:158:in `connect'
> from /lib/ruby/1.8/net/ftp.rb:119:in `initialize'
> ... 7 levels...
> from getp.rb:85:in `get_from'
> from getp.rb:85:in `open'
> from getp.rb:85:in `get_from'
> from getp.rb:120


If you catch the exception ('err') and 'puts err.backtrace', you'll
get the full story in the following form:

...
e.rb:7:in `b'
e.rb:3:in `a'
e.rb:7:in `b'
e.rb:3:in `a'
e.rb:7:in `b'
...

If you do a more complicated printing routine as Matz suggested, you
get this:

...
from e.rb:7:in `b'
from e.rb:3:in `a'
from e.rb:7:in `b'
from e.rb:3:in `a'
from e.rb:7:in `b'
from e.rb:3:in `a'
...

For information purposes, I'd just 'puts err.backtrace' and be done
with it. Note in both cases, the full trace is printed, not "..."!

Gavin



Robert Klemme

11/27/2003 8:59:00 AM

0


"Yukihiro Matsumoto" <matz@ruby-lang.org> schrieb im Newsbeitrag
news:1069888395.324444.21319.nullmailer@picachu.netlab.jp...
> Hi,
>
> In message "Re: Backtrace without skips needed"
> on 03/11/27, "Robert Klemme" <bob.news@gmx.net> writes:
>
> |Before you start, maybe Matz could commment on the idea of having a
> |~/.rubyrc that controls interpreter bahavior (of course together with a
> |switch that allows for ignoring this file). Then maybe he / we / you
> |implement this feature for the complete runtime and all / several
command
> |line switches.
>
> I'd say "no" to the rc idea. I believe it's application matter, not
> language matter, i.e. there can be no common configuration among all
> applications written in Ruby.

Sounds reasonable considering that a change to the rc file could have
suprising side effects on other applications. Thanks for pointing my nose
on that!

Regards

robert