better rearrangement of try/catch block in open(f, cmds)