Géry <gery.o...@gmail.com> added the comment:

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.

----------

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

Reply via email to