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 maggyero
Recipients cameron, docs@python, gvanrossum, iritkatriel, jack__d, lukasz.langa, maggyero, miss-islington, steven.daprano, terry.reedy
Date 2021-08-31.22:55:18
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
No worries, it was almost twenty years ago.

> But it's probably better to raise a dedicated exception in that case and catch it in main(), rather than just calling sys.exit() deep inside the other code.

Yes I agree, and I think you explained very clearly why it is better in the blog post:

> Another refinement is to define a Usage() exception, which we catch in an except clause at the end of main():
> […]
> This gives the main() function a single exit point, which is preferable over multiple return 2 statements.

So I think you made two independent points:

- raising a dedicated exception instead of calling `sys.exit` inside nested functions and catching it inside `main` allows a single exit point;
- calling `sys.exit` outside of `main` instead of inside prevents exiting the Python interpreter in an interactive session.
Date User Action Args
2021-08-31 22:55:18maggyerosetrecipients: + maggyero, gvanrossum, terry.reedy, cameron, steven.daprano, docs@python, lukasz.langa, miss-islington, iritkatriel, jack__d
2021-08-31 22:55:18maggyerosetmessageid: <>
2021-08-31 22:55:18maggyerolinkissue39452 messages
2021-08-31 22:55:18maggyerocreate