system exit in python code example
Example 1: why doesn't sys.exit work?
import sys
try:
sys.exit() # this always raises SystemExit
except SystemExit:
print("sys.exit() worked as expected")
except:
print("Something went horribly wrong") # some other exception got raised
Example 2: python system exit
import sys
age = 17
if age < 18:
sys.exit("Age less than 18")
else:
print("Age is not less than 18")
Example 3: python system exit
import sys
sys.exit(0)