Message400793
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:18 | maggyero | set | recipients:
+ maggyero, gvanrossum, terry.reedy, cameron, steven.daprano, docs@python, lukasz.langa, miss-islington, iritkatriel, jack__d |
2021-08-31 22:55:18 | maggyero | set | messageid: <1630450518.23.0.690099329.issue39452@roundup.psfhosted.org> |
2021-08-31 22:55:18 | maggyero | link | issue39452 messages |
2021-08-31 22:55:18 | maggyero | create | |
|