在 sys.exit 文档中拦截 Python 调用是什么意思?

What is meant by intercepting a Python call in the sys.exit documentation?

Pythondocumentation中说可以在外层拦截exit调用。那么 "intercept at the outside level" 在这里究竟意味着什么? 更具体地说,拦截呼叫是什么意思?

这意味着 except SystemExit 将捕获引发的异常,从而在退出 Python 时拦截尝试的调用。 sys.exit是通过提高SystemExit来实现的,你可以处理。

使用适当的 except 子句:

from sys import exit
try:
    exit("Exiting")
except SystemExit as e:
    print("Well, no you're not.")

工作正常并继续执行。你拦截了。

正如@chepner 所说,通话没有被拦截;对 exit 的调用已完成。生成的异常被您提供的异常处理程序拦截。