[Patches] httplib.HTTP.connect raises wrong exception

Skip Montanaro skip@mojam.com (Skip Montanaro)
Mon, 27 Mar 2000 13:46:53 -0600 (CST)


    Skip> In httplib.HTTP.connect a socket.error is raised when a
    Skip> non-numeric port is given.  Seems to me this is more correctly a
    Skip> ValueError.

    Guido> Hmm...  It explicitly catches the ValueError and raises
    Guido> socket.error.  Why could it be doing this?  (Also, it does the
    Guido> same thing elsewhere in the module.)

Not sure.  The more I see of one module raising other modules' errors, the
more I don't like it since it forces the programmer to be aware of
implementation details of the module being called.

When a module catches an exception I see three valid options:

    1. Recover and continue executing

    2. Embellish the value of the exception (perhaps adding a concrete
       filename or other value), then reraise the same exception.

    3. Raise a new exception defined in this module.  

Both #2 & #3 should invoke raise with the original stack info so as not to
confuse programmers trying to debug their mistakes.

Skip