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

A

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
 
K

Konrad Meyer

--nextPart6517373.X3G5RxmhWM
Content-Type: text/plain;
charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Quoth Andrew Chen:
The ruby interpreter prints out a full trace of the exception.
=20
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.
=20
begin
....
Math.sqrt (-1)
rescue =3D> e
puts e.inspect
end
=20
e only prints out a message.
=20
Am I missing anything real simple?
=20
Thanks
~Andrew Chen

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

=2D-=20
Konrad Meyer <[email protected]> http://konrad.sobertillnoon.com/

--nextPart6517373.X3G5RxmhWM
Content-Type: application/pgp-signature; name=signature.asc
Content-Description: This is a digitally signed message part.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)

iD8DBQBG8JHUCHB0oCiR2cwRApPcAJ4gnmPf6H9PWmf8ezFZbqGLrGEj9gCgnWl7
HqOiM6r6rZ153Ds4SU5CFag=
=NHce
-----END PGP SIGNATURE-----

--nextPart6517373.X3G5RxmhWM--
 
A

Andrew Chen

Konrad said:
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.
 
M

Michael Fellinger

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
 
S

Sylvain Joyeux

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.
 
M

Mitch Mon

I miss Java.

I run into this kind of short sighted decision far too often with Ruby.
Ugh.
 
A

Alex Young

Sylvain said:
... 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.
 
S

Sylvain Joyeux

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
 
R

Roger Pack

Sylvain said:
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
 
A

Andrew Chen

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

Thanks for all the help!
 
K

Kru K.

Michael Fellinger wrote in post #555437:
begin
....
Math.sqrt (-1)
rescue => e
puts e.inspect
puts e.backtrace
ensure
andrew.brain << open("ri"){|ri| ri.read('Exception')}
end

hahah :) nice one
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,830
Latest member
ZADIva7383

Latest Threads

Top