How do `sys.exit`, exit codes and uncaught exceptions relate?
BeginnerConceptExceptions, context managers, files & logging
Answer
sys.exit(n) raises SystemExit; the interpreter exits with n (0 success, non-zero failure). sys.exit("message") prints the message to stderr and exits 1. An uncaught exception prints a traceback and exits 1. A script that catches everything and falls off the end exits 0, which CI treats as success. Shell conventions: 2 for usage errors (argparse and click use it), 126/127 for not executable/not found, 128+N for killed by signal N.
More on Exceptions, context managers, files & logging
How does `try` / `except` / `else` / `finally` work?BeginnerWhy is a bare `except:` (or `except Exception: pass`) dangerous?BeginnerWhat is exception chaining, and what is `raise ... from`?IntermediateWhen should you define custom exception classes?IntermediateWhat is the EAFP vs LBYL style, and which does Python prefer?IntermediateHow does a `with` statement work, and why use it for files?Beginner