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

···

--
Posted via http://www.ruby-forum.com/.

sunglasses?

voice transcription?

···

On Sep 10, 2010, at 23:52 , Brian Candler 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

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

···

On Sep 11, 2:52 am, Brian Candler <b.cand...@pobox.com> 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/.

Sunglasses?

Android phone and touch screen keyboard :frowning:

···

--
Posted via http://www.ruby-forum.com/\.