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

**URL:** <https://www.ruby-forum.com/t/ruby-exception-statement-not-suppressed-within-begin-rescue-end-block/194806>\
**Category:** Ruby\
**Created:** [September 11, 2010, 3:00am UTC](https://www.ruby-forum.com/t/ruby-exception-statement-not-suppressed-within-begin-rescue-end-block/194806 "2010-09-11T03:00:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![RichardOnRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e0b2c6/32.png) [@RichardOnRails](https://www.ruby-forum.com/u/RichardOnRails)\
**Post date:** [September 11, 2010, 3:00am UTC](https://www.ruby-forum.com/t/ruby-exception-statement-not-suppressed-within-begin-rescue-end-block/194806/1 "2010-09-11T03:00:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![RichardOnRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e0b2c6/32.png) [@RichardOnRails](https://www.ruby-forum.com/u/RichardOnRails)\
**Post date:** [September 11, 2010, 8:52am UTC](https://www.ruby-forum.com/t/ruby-exception-statement-not-suppressed-within-begin-rescue-end-block/194806/2 "2010-09-11T08:52:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![RichardOnRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e0b2c6/32.png) [@RichardOnRails](https://www.ruby-forum.com/u/RichardOnRails)\
**Post date:** [September 11, 2010, 9:17am UTC](https://www.ruby-forum.com/t/ruby-exception-statement-not-suppressed-within-begin-rescue-end-block/194806/3 "2010-09-11T09:17:26Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![RichardOnRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e0b2c6/32.png) [@RichardOnRails](https://www.ruby-forum.com/u/RichardOnRails)\
**Post date:** [September 11, 2010, 3:43pm UTC](https://www.ruby-forum.com/t/ruby-exception-statement-not-suppressed-within-begin-rescue-end-block/194806/4 "2010-09-11T15:43:35Z")

</div>

> Sunglasses?

Android phone and touch screen keyboard ☹

---

<div class="post-metadata">

**Author:** ![RichardOnRails](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/e0b2c6/32.png) [@RichardOnRails](https://www.ruby-forum.com/u/RichardOnRails)\
**Post date:** [September 27, 2010, 9:20pm UTC](https://www.ruby-forum.com/t/ruby-exception-statement-not-suppressed-within-begin-rescue-end-block/194806/5 "2010-09-27T21:20:55Z")

</div>

On Sep 11, 2:52 am, Brian C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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 🙂 My delay in  
responding, for which I apologize, occurred because I distracted by  
another project.

Best wishes,  
Richard
