14. Handling Errors Without Leaking Data
Show clear messages to users without exposing system details. Log full errors for developers safely.
Example
import logging
logging.basicConfig(filename="app.log", level=logging.ERROR)
def load_config():
try:
with open("config.yaml") as f:
return f.read()
except FileNotFoundError:
print("Configuration file missing.")
logging.exception("Missing configuration file.")
✅ Lesson: Show user-friendly messages but log technical details privately.