Python style: exceptions vs. sys.exit()
tjreedy at udel.edu
Tue Sep 23 23:49:32 CEST 2008
> 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
> or should the exception propagate to the calling program which
> handles the issue?
Yes -- with an informative error message.
If the caller ignores the exception, the program will exit with a full
stack trace anyway.
More information about the Python-list