Question on defining hier error types: Is this OK?

Discussion in 'Ruby' started by jim@freeze.org, Oct 25, 2004.

  1. Guest

    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?

    --
    Jim Freeze
     
    , Oct 25, 2004
    #1
    1. Advertising

  2. wrote:
    > 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
     
    Joel VanderWerf, Oct 25, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jack In A Box

    niek hier

    Jack In A Box, Dec 3, 2004, in forum: HTML
    Replies:
    0
    Views:
    465
    Jack In A Box
    Dec 3, 2004
  2. johny smith
    Replies:
    8
    Views:
    449
    Peter Koch Larsen
    Jul 2, 2004
  3. Joe Laughlin

    defining new types

    Joe Laughlin, Oct 21, 2004, in forum: C++
    Replies:
    10
    Views:
    604
    Richard Herring
    Oct 25, 2004
  4. Michael Yanowitz

    Defining our own types?

    Michael Yanowitz, Aug 16, 2006, in forum: Python
    Replies:
    3
    Views:
    297
    tobiah
    Aug 17, 2006
  5. flounder
    Replies:
    4
    Views:
    532
    flounder
    Apr 2, 2009
Loading...

Share This Page