4 ms·
Can someone explain the last bit: print(f"Unexpected error: {error}") sys.exit(1) How is that any different than just letting the exception throw
by valbaca 2y ago
Can someone explain the last bit:
print(f"Unexpected error: {error}")
sys.exit(1)
How is that any different than just letting the exception throw all the way out?
Is all this doing is making sure the exit code is 1 instead of some other non-zero value?
I'm not seeing how this is any better than just letting the program hard-crash.
(I am asking in earnest. I'm getting back into Python and wanting to know what's generally preferred)
- krysp 2y agoIt gives you control over the output of your program (and as you mention, the exact error code - which probably should be 1 in this instance). It's often more user friendly to print a short human-readable message (or nothing) than to dump a huge stack trace. YMMV, if this is an internal dev tool then the opposite might be true!
- whinvik 2y agoI feel like both of them should crash the application. The only benefit is that you don't see the full stack trace in production, which depending on circumstances you don't want to be shown.