How do you find what exceptions a class can throw?

2QdxY4RzWzUUiLuE at potatochowder.com 2QdxY4RzWzUUiLuE at potatochowder.com
Sun Dec 20 12:05:26 EST 2020


On 2020-12-20 at 16:02:53 +0000,
Regarding "Re: How do you find what exceptions a class can throw?,"
Chris Green <cl at isbd.net> wrote:

> Stefan Ram <ram at zedat.fu-berlin.de> wrote:
> > Chris Green <cl at isbd.net> writes:
> > >I am using poplib.POP3_SSL() and I want to know what exceptions can be
> > >thrown when I instantiate it.  Presumably it inherits them because
> > >there's nothing much in the documentation page for poplib.POP3_SSL().
> > 
> >   Both Java and C++ have tried to introduce a static
> >   declaration of exceptions IIRC, but IIRC this was less
> >   popular as it led to problems.
> > 
> >   Ultimately, it is not possible to tell what exceptions 
> >   a call might throw. In such a case, it may help to explain
> >   to the newsgroup why this information is needed.
> > 
> So that, as is always advised, I can catch the specific exception
> being thrown!

To the point:  what are you going to do with it once you catch it?

Are you prepared to handle every exception individually, or are you
fishing for exceptions that you think might be worth catching?

Remember, you get reporting (a traceback) and program cleanup and exit
for free.  What will catching an exception *add* to the user experience?


More information about the Python-list mailing list