(newbye) exceptions list for python3 classes

Ben Finney ben+python at benfinney.id.au
Mon Jun 24 19:27:41 EDT 2013


chrem <usenetNoSpam at chr1st0ph9.eu> writes:

> Hi,

Howdy, congratulations on finding the Python programming language.

> what is the best way to find out all exceptions for a class?

Python is not Java. Your program doesn't need to know everything that
might happen; you should catch only those exceptions you can actually
deal with usefully, and let any others propagate.

> E.g. I want to find out all exceptions related to the zipfile (I'm
> searching for the Bad password exception syntax).

The documentation will describe the behaviour of the module; many
exceptions are implied by that (e.g. if the module deals with the
filesystem, you can expect OSError to be raised under certain
conditions).

Other exceptions will come from deeper within Python; e.g. if you give
text in a bad encoding you can expect UnicodeDecodeError, or if you give
it an object that can't be handled as expected you might get a TypeError.

But trying to get a complete set of all exceptions that might be raised
is a fool's errand. It would be futile, both because everything in
Python is an object and can therefore raise whatever exceptions are
appropriate, and also because even if you knew a complete set, you can't
usefully do anything consistent with such a huge set of exception types.

So, what is it you want to do one you know a set of exception types that
can be raised by the code?

> thanks for your help or feedback,

Hope that helps, and good fortune to you in learning to code Pythonically!

-- 
 \          “When we talk to God, we're praying. When God talks to us, |
  `\         we're schizophrenic.” —Jane Wagner, via Lily Tomlin, 1985 |
_o__)                                                                  |
Ben Finney




More information about the Python-list mailing list