Ruby exception statement not suppressed within begin-rescue-end block

R

RichardOnRails

HI,

I've got the code below. it creates the output:

Exception `NameError' at ReformChartNames.rb:8 - uninitialized
constant DATA
"__END__" statement or subsequent directory-name missing
Quitting job

I thought the "Exception" statement should not be generated because I
rescued from and errors. So, what's up?

Thanks in Advance,
Richard

=== code ===
[snip]
$DEBUG = true
$source_directory_name

begin
$source_directory_name =
DATA.readline # Line # 8
rescue
puts %<"__END__" statement or subsequent directory-name missing
\nQuitting job>
STDOUT.flush
exit
end

class ReformChartNames
def initialize
@source_dir_name = $source_directory_name.chomp
unless File.directory?(@source_dir_name)
puts %<ERROR: "%s" is not a valid directory name> %
[@source_dir_name]
exit
end
end
end


rcn = ReformChartNames.new
puts %<Got ReformChartNames object "rcn"> if $DEBUG
 
B

Brian Candler

A bare 'rescue' is short for 'rescue StandardError', and catches only
sunglasses of that. If you want to rescue everything then 'rescue
Exception', but beware that also catches programmer errors, system
problems like out of memory etc.

Google "ruby exception hierarchy" for more.

To use DATA, put __END__ at the end of your code followed by the data
 
R

Ryan Davis

A bare 'rescue' is short for 'rescue StandardError', and catches only
sunglasses of that. If you want to rescue everything then 'rescue
Exception', but beware that also catches programmer errors, system
problems like out of memory etc.

Google "ruby exception hierarchy" for more.

To use DATA, put __END__ at the end of your code followed by the data

sunglasses?

voice transcription?
 
R

RichardOnRails

A bare 'rescue' is short for 'rescue StandardError', and catches only
sunglasses of that. If you want to rescue everything then 'rescue
Exception', but beware that also catches programmer errors, system
problems like out of memory etc.

Google "ruby exception hierarchy" for more.

To use DATA, put __END__ at the end of your code followed by the data

Hi Brian,

Thanks for your excellent response, not withstanding the sunglasses I
must have been wearing when I screwed up :) My delay in
responding, for which I apologize, occurred because I distracted by
another project.

Best wishes,
Richard
 

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,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top