First page Back Continue Last page Overview Graphics

Using sys.exit()

import sys

def f():

print("Whatever!")

sys.exit("The end")

print("Main program!")

try:

f()

except SystemExit as msg:

print("Exception caught:", msg)

Main program!

Whatever!

Exception caught: The end

import sys

def f():

print("Whatever!")

sys.exit()

print("Main program!")

f()

Main program!

Whatever!