Forum: Ruby on Rails Trapping specific errors

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Joerg D. (Guest)
on 2006-02-27 14:16
Hi,

I have a begin rescue clause and want to trap for specific errors

begin
  cause error
rescue Excpetion => err
  case err
    when SocketError
      do stuff
    when ... # trap for ErrNo::EINVAL
  end
end

Say I get the error ErrNo::EINVAL ... how/where can I find out what the
Excpetion for it is named?

I have tries ErrNo::EINVAL, ErrNo::EINVALError, EINVALError, but none of
these seem to trap the exception ....

Any help please

Thanks
Joerg
Joerg D. (Guest)
on 2006-02-27 15:11
I found the answer in my PickAxe.

Errors like Errno:: are SystemCallErrors that the operating throws, and
they are contained in a module called Errno ... <- note the small 'n'.

So to trap an invalid argument error for example, use Errno::EINVAL

No need to append it with 'Error' either.

Sorry for noise.

Joerg D. wrote:
> Hi,
>
> I have a begin rescue clause and want to trap for specific errors
>
> begin
>   cause error
> rescue Excpetion => err
>   case err
>     when SocketError
>       do stuff
>     when ... # trap for ErrNo::EINVAL
>   end
> end
>
> Say I get the error ErrNo::EINVAL ... how/where can I find out what the
> Excpetion for it is named?
>
> I have tries ErrNo::EINVAL, ErrNo::EINVALError, EINVALError, but none of
> these seem to trap the exception ....
>
> Any help please
>
> Thanks
> Joerg
This topic is locked and can not be replied to.