foo.rb:7: undefined local variable or method `foo’ for #Object:0x401dbce0 (NameError)
which IS in fact writtne to the file ‘stderr’, but not untill AFTER the script
finishes? what gives?
i wanted to use this technique to catch NameErrors errors from cgi scripts…
-a
···
–
====================================
Ara Howard
NOAA Forecast Systems Laboratory
Information and Technology Services
Data Systems Group
R/FST 325 Broadway
Boulder, CO 80305-3328
Email: ahoward@fsl.noaa.gov
Phone: 303-497-7238
Fax: 303-497-7259
====================================
This raises an exception and you don't catch it. Consequence the error
message is printed in 'stderr' when ruby exit (i.e. it don't execute the
lines after the error)
begin
$stderr.reopen File.open ‘stderr’, ‘w’
$stderr.sync = true
foo # this raises an exception…
ensure
$stderr.flush
puts IO.readlines ‘stderr’, ‘r’
puts FILE
end
this outputs only ‘foo.rb’
eli > ruby foo.rb
foo.rb
eli > cat stderr
foo.rb:9: undefined local variable or method `foo’ for #Object:0x401dbce0 (NameError)
so the file IS created… this is really bizare…
is it a bug in ruby?
here is another hint : if i also do $stderr.close after $stderr.flush, the file
is not even created!
-a
···
On Sat, 9 Nov 2002, ts wrote:
This raises an exception and you don’t catch it. Consequence the error
message is printed in ‘stderr’ when ruby exit (i.e. it don’t execute the
lines after the error)
–
====================================
Ara Howard
NOAA Forecast Systems Laboratory
Information and Technology Services
Data Systems Group
R/FST 325 Broadway
Boulder, CO 80305-3328
Email: ahoward@fsl.noaa.gov
Phone: 303-497-7238
Fax: 303-497-7259
====================================
Ara Howard
NOAA Forecast Systems Laboratory
Information and Technology Services
Data Systems Group
R/FST 325 Broadway
Boulder, CO 80305-3328
Email: ahoward@fsl.noaa.gov
Phone: 303-497-7238
Fax: 303-497-7259
====================================
and this works for both examples (foo, 1/0)… i was under the impression
that a :
rescue => err
clause would catch all errors, since i thought all errors were subclasses of
StandardError - this obviously is not the case. since i had to explicitly
catch the NameError in order to redirect to file. my goal was to redirect ALL
stderr to file in cgi programs, since any stderr output causes apache to print
an error page, and also catch all exceptions - in this was, i can generate
meaningfull error pages when debugging cgi programs. any better ways to do
this you know of? the advantage of this technique is that one can check to
see if anything was written the stderr file, and decide what to do then, if
$stderr is not redirected you do not have this option.
-a
···
On Sun, 10 Nov 2002, ts wrote:
–
====================================
Ara Howard
NOAA Forecast Systems Laboratory
Information and Technology Services
Data Systems Group
R/FST 325 Broadway
Boulder, CO 80305-3328
Email: ahoward@fsl.noaa.gov
Phone: 303-497-7238
Fax: 303-497-7259
====================================