Replace sys.exit calls by exceptions