can't rescue Errno::EBADF

M

Mr_Tibs

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
 
L

Luis Parravicini

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

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
 
M

Mr_Tibs

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
 
N

Nobuyoshi Nakada

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top