python/try.py

import time

print(__file__ , "begin text exception with ctrl-c")
def sleepUntilInterrupt(l):
    try:
        for i in range(5):
            print("sleepUntilInterrupt", l)
            time.sleep(2)
    except BaseException as e:
        print("sleepUntilInterrupt exception", repr(e), type(e))
        if l < 2:
            sleepUntilInterrupt(l+1)
    else:
        print("sleepUntilInterrupt else", l)
    finally:
        print("sleepUntilInterrupt finally", l)

sleepUntilInterrupt(0)