From: Matthew Pounsett on
[accidentally posted this from an non-subscribed address a few minutes ago .. hopefully it doesn't show up twice]

I'm trying to add some missing handlers to the Errno module on my system. But, clearly I'm missing something here, as I'm getting an error I don't understand when I try a raise using any of them.

My test code:

irb(main):001:0> module Errno
irb(main):002:1> class EFTYPE < SystemCallError; end
irb(main):003:1> end
=> nil
irb(main):004:0> raise Errno::EFTYPE, "trying to raise an error here", caller
TypeError: can't convert Module into Integer
from (irb):4:in `initialize'
from (irb):4:in `exception'
from (irb):4:in `raise'
from (irb):4
from /opt/local/bin/irb:12:in `<main>'
irb(main):005:0>

I'm using things like the webrick standard library as an example here, but clearly I've got something wrong. Anyone have any suggestions?

Matt

From: Yaser Sulaiman on
[Note: parts of this message were removed to make it a legal post.]

Hi Matt.

I think you need to define Errno::EFTYPE::Errno and assign it an integer.

module Errno
class EFTYPE < SystemCallError
Errno = 42
end
end

Now in IRB, you'll get something like the following:

irb(main):014:0> raise Errno::EFTYPE, "trying to raise an error here"
Errno::EILSEQ: Illegal byte sequence - trying to raise an error here
from (irb):14

Notice that 42 is the "integer operating system error number corresponding
to" [1] Errno::EILSEQ. You may want to select a different (the
appropriate?) value.

HTH,
Yaser

[1]: http://ruby-doc.org/docs/ProgrammingRuby/html/ref_m_errno.html