Python exceptions try/except (example from my static site generator project):
def write_about_json(project_name, about_dictionary):
try:
with open(‘projects/’ + project_name + ‘/settings/about.json’, ‘w’) as json_file:
json.dump(about_dictionary, json_file)
except IOError:
print(“Error: failed to write to about.json”)
sys.exit()