Question on defining hier error types: Is this OK?

J

jim

Hi

I was defining a hierachical error type today and realized
that I had inheritied from a class before it was closed.

It seems to work nicely, but was just wondering why.

Below is an example:

module A

class MyClassError < StandardError
class NoBlockError < MyClassError; end
class IOError < MyClassError; end
...
end#class MyClassError


class MyClass
...
raise MyClassError::NoBlockError
...
raise MyClassError::IOError
...
end#class MyClass

end#module A

I like the way this turned out. Does anyone see a problem with doing this?
 
J

Joel VanderWerf

Hi

I was defining a hierachical error type today and realized
that I had inheritied from a class before it was closed.

It seems to work nicely, but was just wondering why.

Below is an example:

module A

class MyClassError < StandardError
class NoBlockError < MyClassError; end
class IOError < MyClassError; end
...
end#class MyClassError


class MyClass
...
raise MyClassError::NoBlockError
...
raise MyClassError::IOError
...
end#class MyClass

end#module A

I like the way this turned out. Does anyone see a problem with doing this?

My guess: Closing a class isn't really significant, since it can be
reopened at any time. The class has been fully defined when the "class
XXX < ..." line has been executed. For consistency, the following would
have to be equivalent:

class A
do_something_with_A
end

and

class A
end # close the class

class A
do_something_with_A
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,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top