Can't rescue Errno::EBADF

Hi,

I can’t seem to do a very simple thing: I cannot rescue a Errno::EBADF
exception in my code. I know it is a Errno::EBADF exception, since I
can rescue it through the generic exception type (Exception) and then
I print the message. However, if I replace the rescue statement from
“rescue Exception => e” to “rescue Errno::EBADF”, the code doesn’t go
through the rescue block.

Am I doing something obvisouly wrong or is there something tricky
about catching this type of exceptions?

I want to mention that I’m not using Rails or rake (all the posts that
I’ve seen on Errno::EBADF are on these 2 subjects).

Thanks,
Tiberiu

On 9/5/07, Mr_Tibs [email protected] wrote:

about catching this type of exceptions?

I want to mention that I’m not using Rails or rake (all the posts that
I’ve seen on Errno::EBADF are on these 2 subjects).

Thanks,
Tiberiu

Hi, could it be something else from your code? I’ve tried the
following code and it catches the exception:

begin
raise Errno::EBADF
rescue Errno::EBADF
puts “got it: #{$!}”
end

Hi,

Thanks for the reply. I did try the same thing and I noticed it works.
I really don’t know what I’m doing wrong in my code. Same thing
happens when I try to catch Errno::ETIMEDOUT. Even when I make my own
Exception class it does work as expected, but not for these 2
exception types.

Tiberiu

Hi,

At Thu, 6 Sep 2007 07:40:07 +0900,
Mr_Tibs wrote in [ruby-talk:267813]:

Thanks for the reply. I did try the same thing and I noticed it works.
I really don’t know what I’m doing wrong in my code. Same thing
happens when I try to catch Errno::ETIMEDOUT. Even when I make my own
Exception class it does work as expected, but not for these 2
exception types.

Does it work with SystemCallError?

With rescuing Exception, is the class of the exception really
same as Errno::EBADF? try:

rescue Exception => e
p e.class
p e.class.ancestors
p e.class == Errno::EBADF
end

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