Maybe you can try to put your code in try catch like
def main(): try: .... except Exception as e: print(f"An error occurred: {e}") finally: input("Press Enter to exit...") if __name__ == "__main__": main()