How do you find what exceptions a class can throw?

Chris Green cl at isbd.net
Sun Dec 20 12:06:47 EST 2020


Stefan Ram <ram at zedat.fu-berlin.de> wrote:
> Chris Green <cl at isbd.net> writes:
> >So that, as is always advised, I can catch the specific exception
> >being thrown!
> 
>   It usually is advisable to be more specific when catching
>   exceptions. The worst thing to do is surely a bare "except:"
>   which then ignores the exception.
> 
>   A general "except Exception:" is slightly better, since it
>   will not catch SystemExit and KeyboardInterrupt exceptions.
> 
>   According to me, you should only catch a specific exception
>   if you know better than your caller what to do in this case.
>   Otherwise just let it pass through to your caller.
> 
> 
"better than your caller"???  If I ignore the exception then the
program just exits, if I want the program to do something useful about
it (like try again) then I have to catch the specific exception as I
don't want to try again with other exceptions.

-- 
Chris Green
·


More information about the Python-list mailing list