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

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

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

On Sep 10, 2010, at 23:52 , Brian C. wrote:

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?

Sunglasses?

Android phone and touch screen keyboard :frowning:

On Sep 11, 2:52 am, Brian C. [email protected] wrote:

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

Posted viahttp://www.ruby-forum.com/.

Hi Brian,

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

Best wishes,
Richard

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs