Python style: exceptions vs. sys.exit()

Larry Bates larry.bates at vitalEsafe.com
Tue Sep 23 23:15:26 CEST 2008


Drake wrote:
> I have a general question of Python style, or perhaps just good
> programming practice.
> 
> My group is developing a medium-sized library of general-purpose
> Python functions, some of which do I/O. Therefore it is possible for
> many of the library functions to raise IOError Exceptions. The
> question is: should the library function be able to just dump to
> sys.exit() with a message about the error (like "couldn't open this
> file"), or should the exception propagate to the calling program which
> handles the issue?
> 
> Thanks in advance for anyone who can either answer my question or
> point me to where this question has already been answered.
> 

IMHO libraries should always just let the exception propagate up to the caller. 
  That allows the caller the option of taking the appropriate action.

-Larry



More information about the Python-list mailing list