Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vblackburn0305/39d4946b71ed94c1f1bfe57fd8704fd3 to your computer and use it in GitHub Desktop.
Save vblackburn0305/39d4946b71ed94c1f1bfe57fd8704fd3 to your computer and use it in GitHub Desktop.
Part 1:
<def throw_me_an_error():
try:
val1 = 14
val2 = 0
return val1 / val2
except ZeroDivisionError as e:
print(f"Error occurred: {e}")
throw_me_an_error()>
Part 2:
<# The finally block ensures that the file is closed even if an exception occurs during the write process. This helps avoid leaving files open.>
Part 3:
<import json
data = '{"invalid_json_key": "value"}'
try:
parsed_data = json.loads(data)
print(parsed_data)
except json.JSONDecodeError as e:
print(f"JSON import error: {e}")>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment