Python style: exceptions vs. sys.exit()

Lie Lie.1296 at gmail.com
Sun Sep 28 11:55:03 EDT 2008


On Sep 25, 3:05 pm, Bruno Desthuilliers <bruno.
42.desthuilli... at websiteburo.invalid> wrote:
> Steven D'Aprano a écrit :
>
> > On Wed, 24 Sep 2008 17:11:28 -0400, Ross Ridge wrote:
>
> >> Plenty of people were quick to say that the exception should be passed
> >> through to the caller.  No one said this behaviour should be documented.
> >>  There may be little practical difference bewteen calling sys.exit()
> >> after printing an error and progating an exception if no one using the
> >> library knows that it could generate that exception in those
> >> circumstances.
>
> > That's true, I didn't explicitly say that the library should be
> > documented. Nor did I say that it shouldn't be riddled with bugs. There's
> > little practical difference between a buggy library and one that raises
> > unexpected (i.e. undocumented) exceptions either.
>
> Also note that there are quite a couples cases where the library authors
> themselves cannot predict which exception types may be raised - as soon
> as the library functions expect callback functions, file-like or
> dict-like or whatever-like objects etc, it's the caller's responsability
> to handle the exceptions that may be raised by what *he* passes to the
> library...

No, the library author can always predict which exception his library
may raise. If a callback function, file-like, dict-like, etc raises an
exception, it is not his libraries' exception anymore and is not his
responsibility. In that case we should refer to the documentation for
the callback/etc/etc instead of the documentation for the library.



More information about the Python-list mailing list