Go Back   Rhinocerus > Newsgroup > Newsgroup comp.lang.ruby

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 07-09-2007, 01:07 AM
Joel VanderWerf
Guest
 
Posts: n/a
Default set_trace_func and exceptions


There seem to be two problems with set_trace_func (or things I don't
understand):

1. The following program does not print "done". It does not raise an
exception. It *does* set the program's return code to false.

set_trace_func proc { || }
puts "done"

It's not a correct program, but I expected an ArgumentError, rather than
a silent exit.

2. The following program does not print the exception or "done". It does
not raise an exception to the top level. It *does* set the program's
return code to false.

set_trace_func proc { |event, file, line, id, binding, classname|
raise "foobar"
}

begin
x = 1
rescue => ex
p ex
end

puts "done"

Is it impossible to safely raise an exception inside of a trace func?

This is in ruby 1.8.4 and 1.8.6.

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

Reply With Quote
Alt Today
Advertising
 
and become member of Rhinocerus
Standard Sponsored Links

  #2 (permalink)  
Old 07-10-2007, 06:47 AM
Robert Klemme
Guest
 
Posts: n/a
Default Re: set_trace_func and exceptions

2007/7/9, Joel VanderWerf <vjoel@path.berkeley.edu>:
>
> There seem to be two problems with set_trace_func (or things I don't
> understand):
>
> 1. The following program does not print "done". It does not raise an
> exception. It *does* set the program's return code to false.
>
> set_trace_func proc { || }
> puts "done"
>
> It's not a correct program, but I expected an ArgumentError, rather than
> a silent exit.
>
> 2. The following program does not print the exception or "done". It does
> not raise an exception to the top level. It *does* set the program's
> return code to false.
>
> set_trace_func proc { |event, file, line, id, binding, classname|
> raise "foobar"
> }
>
> begin
> x = 1
> rescue => ex
> p ex
> end
>
> puts "done"
>
> Is it impossible to safely raise an exception inside of a trace func?
>
> This is in ruby 1.8.4 and 1.8.6.


It does not make sense to allow exceptions to be thrown from
set_trace_func. I do agree however that at least some form of warning
should be generated but I think the exception should be ignored
otherwise. But then again, since set_trace_func is more of a
debugging feature it's not too important to fix it IMHO.

Kind regards

robert

Reply With Quote
  #3 (permalink)  
Old 07-10-2007, 05:02 PM
Joel VanderWerf
Guest
 
Posts: n/a
Default Re: set_trace_func and exceptions

Robert Klemme wrote:
...
> It does not make sense to allow exceptions to be thrown from
> set_trace_func. I do agree however that at least some form of warning
> should be generated but I think the exception should be ignored
> otherwise. But then again, since set_trace_func is more of a
> debugging feature it's not too important to fix it IMHO.


But set_trace_func has been used for more than debugging
(Binding.of_caller, right?) Arguably, that's a kludge.

What if you are using set_trace_func as a debugging tool to detect some
problem (memory management, for example), and you want to stop or signal
the program when the problem is detected?

This issue came up for me because I was tinkering with some code for the
"CPU/Memory limiting" thread. I was trying to use set_trace_func in a
stupid way to count "steps" per thread, as a surrogate for cpu cycles,
and raise an exception when a limit was exceeded.

Perhaps this use of exceptions (as a way of signaling back to the
calling code) is not appropriate with set_trace_func. There are other
ways to do this that would work in the context of the "CPU/Memory
limiting" thread.

After thinking about it, I guess the only change I would ask for is some
kind of warning (if running with -w) that an exception happened in the
trace func, rather than a silent exit from the program.

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

Reply With Quote
 
Reply

Thread Tools
Display Modes

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 Off
Pingbacks are Off
Refbacks are Off




All times are GMT. The time now is 03:51 PM.


Copyright ©2009

LinkBacks Enabled by vBSEO 3.3.0 RC2 © 2009, Crawlability, Inc.