This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author aroberge
Recipients aroberge, docs@python, gtitze, iritkatriel, sobolevn
Date 2022-01-07.21:10:25
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>

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:

 +-- 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).
Date User Action Args
2022-01-07 21:10:25arobergesetrecipients: + aroberge, docs@python, sobolevn, iritkatriel, gtitze
2022-01-07 21:10:25arobergesetmessageid: <>
2022-01-07 21:10:25arobergelinkissue46291 messages
2022-01-07 21:10:25arobergecreate