Andre Roberge <andre.robe...@gmail.com> added the comment:

Irit:


In all the books and tutorials I have seen, the advice is to try to catch 
specific exceptions whenever possible or, *at most*, to catch Exception (and 
not BaseException).  This is to allow, for example, a program to be interrupted 
by a KeyboardInterrupt.

As you know, the hierarchy is as follows:

BaseException
 +-- SystemExit
 +-- KeyboardInterrupt
 +-- GeneratorExit
 +-- Exception
      +-- all others

If specific action to do some cleanup before a SystemExit (usually the result 
of calling sys.exit()) or catching some KeyboardInterrupt (which is generally 
NOT done via a raise statement), then these specific exception should be caught.
The documentation refers to GeneratorExit as not indicating an error needing to 
be caught by users.

For this advice (catching Exception and not BaseException) to be correct, users 
should be advised (as they are in the tutorial) to raise exceptions derived 
from Exception (and not BaseException).

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue46291>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to