Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > exception backtrace for ruby/tk programs

Reply
Thread Tools

exception backtrace for ruby/tk programs

 
 
Ferenc Engard
Guest
Posts: n/a
 
      10-08-2003
Hello,

I suffered with really hard debugging sessions when an unexpected
exception was thrown from a ruby callback in a ruby/tk application, as
the tk error dialog box showed only the error message itself and no
backtrace. I have had to modify TkCore.callback() to reveal the
backtrace.

Don't you miss this information? Can this be done in another way? If
not, then here is the simple patch, maybe it can be put into the
mainstream code.

------------------------------------------------------------------
root@domesticus:/usr/lib/ruby/1.8# diff -u tk.rb.old tk.rb
--- tk.rb.old 2003-10-09 01:18:38.000000000 +0200
+++ tk.rb 2003-10-09 01:40:47.000000000 +0200
@@ -772,7 +772,13 @@

#_get_eval_string(TkUtil.eval_cmd(TkCore::INTERP.t k_cmd_tbl[arg.shift],
# *arg))
cb_obj = TkCore::INTERP.tk_cmd_tbl[arg.shift]
- cb_obj.call(*arg)
+ begin
+ cb_obj.call(*arg)
+ rescue
+ # Append the backtrace to the message, so it can be displayed in
the
+ # Tk error dialog window.
+ raise $!, "#{$!} - backtrace: \n#{$!.backtrace.join("\n")}"
+ end
end

def load_cmd_on_ip(tk_cmd)
------------------------------------------------------------------

Bye:
Ferenc
 
Reply With Quote
 
 
 
 
Ara.T.Howard
Guest
Posts: n/a
 
      10-09-2003
On Wed, 8 Oct 2003, Ferenc Engard wrote:

> Hello,
>
> I suffered with really hard debugging sessions when an unexpected
> exception was thrown from a ruby callback in a ruby/tk application, as
> the tk error dialog box showed only the error message itself and no
> backtrace. I have had to modify TkCore.callback() to reveal the
> backtrace.
>
> Don't you miss this information?


> Can this be done in another way?


how about something simple like this?

~/eg/ruby > cat exception.rb
class Exception
alias __to_s to_s
def to_s; __to_s << "\n" << backtrace.map{|t| "\t#{t}\n"}.join; end
end

def method
raise 'foo'
end

method

~/eg/ruby > ruby exception.rb
exception.rb:8:in `method': foo (RuntimeError)
exception.rb:8:in `method'
exception.rb:11

from exception.rb:11

of course perhpas one should use inspect, but you get the idea...

-a


> If not, then here is the simple patch, maybe it can be put into the
> mainstream code.
>
> ------------------------------------------------------------------
> root@domesticus:/usr/lib/ruby/1.8# diff -u tk.rb.old tk.rb
> --- tk.rb.old 2003-10-09 01:18:38.000000000 +0200
> +++ tk.rb 2003-10-09 01:40:47.000000000 +0200
> @@ -772,7 +772,13 @@
>
> #_get_eval_string(TkUtil.eval_cmd(TkCore::INTERP.t k_cmd_tbl[arg.shift],
> # *arg))
> cb_obj = TkCore::INTERP.tk_cmd_tbl[arg.shift]
> - cb_obj.call(*arg)
> + begin
> + cb_obj.call(*arg)
> + rescue
> + # Append the backtrace to the message, so it can be displayed in
> the
> + # Tk error dialog window.
> + raise $!, "#{$!} - backtrace: \n#{$!.backtrace.join("\n")}"
> + end
> end
>
> def load_cmd_on_ip(tk_cmd)
> ------------------------------------------------------------------
>
> Bye:
> Ferenc
>


====================================
| Ara Howard
| NOAA Forecast Systems Laboratory
| Information and Technology Services
| Data Systems Group
| R/FST 325 Broadway
| Boulder, CO 80305-3328
| Email:
| Phone: 303-497-7238
| Fax: 303-497-7259
| The difference between art and science is that science is what we understand
| well enough to explain to a computer. Art is everything else.
| -- Donald Knuth, "Discover"
| ~ > /bin/sh -c 'for lang in ruby perl; do $lang -e "print \"\x3a\x2d\x29\x0a\""; done'
====================================
 
Reply With Quote
 
 
 
 
Hidetoshi NAGAI
Guest
Posts: n/a
 
      10-16-2003
Hi,

From: Ferenc Engard <>
Subject: exception backtrace for ruby/tk programs
Date: Thu, 9 Oct 2003 08:50:56 +0900
Message-ID: <>
> I suffered with really hard debugging sessions when an unexpected
> exception was thrown from a ruby callback in a ruby/tk application, as
> the tk error dialog box showed only the error message itself and no
> backtrace. I have had to modify TkCore.callback() to reveal the
> backtrace.
>
> Don't you miss this information? Can this be done in another way? If
> not, then here is the simple patch, maybe it can be put into the
> mainstream code.


I think the information is too verbose. So, I truncate the backtrace
based on the difference of the backtrace between pre- and post-calling
callback-body. However, if no exception, it is waste of resources to
get and keep the backtrace. On the CVS, I implement that the particulars
are displayed only if $DEBUG == true.
--
Hidetoshi NAGAI ()

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
not swallowed levels of the backtrace on unrescued exception Roger Pack Ruby 1 02-08-2009 06:09 PM
autoprint of exception backtrace mortee Ruby 1 10-29-2007 07:20 PM
Why does Exception#backtrace hate me so? Bill Kelly Ruby 0 03-07-2007 08:18 AM
Object#caller and Exception#backtrace Ben Giddings Ruby 0 02-08-2005 06:07 PM
re-raising an exception with the original backtrace Joel VanderWerf Ruby 0 11-28-2003 10:37 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57