# Changing dirs and exceptions

**URL:** <https://www.ruby-forum.com/t/changing-dirs-and-exceptions/101359>\
**Category:** Ruby\
**Created:** [August 4, 2006, 2:33pm UTC](https://www.ruby-forum.com/t/changing-dirs-and-exceptions/101359 "2006-08-04T14:33:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![viciu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/7ba0ec/32.png) [@viciu](https://www.ruby-forum.com/u/viciu)\
**Post date:** [August 4, 2006, 2:33pm UTC](https://www.ruby-forum.com/t/changing-dirs-and-exceptions/101359/1 "2006-08-04T14:33:03Z")

</div>

Hi!  
I’ve been stuck with simple thing - I’m trying to change dir into not  
existant directory. I’m using following code:

dir=“no\_such\_one”  
begin  
Dir.chdir(dir)  
rescue  
into\_dir = false; #we didn’t make it  
end

And resuce does not catch this:

Exception `Errno::ENOENT’ at ./test.rb:33 - No such file or directory -  
no\_such\_one

But Errno::ENOENT is child of StandardError, which should be catched by  
default. So I’m probably making some stupid mistake - but I can not find  
what one. Could someone help me?

---

<div class="post-metadata">

**Author:** ![viciu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/7ba0ec/32.png) [@viciu](https://www.ruby-forum.com/u/viciu)\
**Post date:** [August 4, 2006, 2:37pm UTC](https://www.ruby-forum.com/t/changing-dirs-and-exceptions/101359/2 "2006-08-04T14:37:31Z")

</div>

Witold R. wrote:

> And resuce does not catch this:
> 
> Exception `Errno::ENOENT’ at ./test.rb:33 - No such file or directory -  
> no\_such\_one

OK to be clear - execution is not stopped at this point (so resue is  
somehow working) but I was not expecting this message on stderr. How to  
get rid off this message?

---

<div class="post-metadata">

**Author:** ![viciu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/7ba0ec/32.png) [@viciu](https://www.ruby-forum.com/u/viciu)\
**Post date:** [August 4, 2006, 2:45pm UTC](https://www.ruby-forum.com/t/changing-dirs-and-exceptions/101359/3 "2006-08-04T14:45:15Z")

</div>

Hi,

At Fri, 4 Aug 2006 21:33:10 +0900,  
Witold R. wrote in [ruby-talk:206240]:

> Exception `Errno::ENOENT’ at ./test.rb:33 - No such file or directory -  
> no\_such\_one

Seems like a message displayed when $DEBUG is turned on.

---

<div class="post-metadata">

**Author:** ![viciu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/v/7ba0ec/32.png) [@viciu](https://www.ruby-forum.com/u/viciu)\
**Post date:** [August 4, 2006, 2:52pm UTC](https://www.ruby-forum.com/t/changing-dirs-and-exceptions/101359/4 "2006-08-04T14:52:58Z")

</div>

unknown wrote:

> > Exception `Errno::ENOENT’ at ./test.rb:33 - No such file or directory -  
> > no\_such\_one
> 
> Seems like a message displayed when $DEBUG is turned on.

That was it ;-)) In #! line I have left -d switch. It time for break 😉
