Skip to content

Instantly share code, notes, and snippets.

@tschreiner
Created January 22, 2024 15:11
Show Gist options
  • Save tschreiner/dd9f290ebc8fc65f96dffc1d84fa59e7 to your computer and use it in GitHub Desktop.
Save tschreiner/dd9f290ebc8fc65f96dffc1d84fa59e7 to your computer and use it in GitHub Desktop.
Exception handler for sending unhandled exceptions to the developer
import traceback
import smtplib
from email.mime.text import MIMEText
def send_error_to_developer(error_details):
msg = MIMEText(error_details)
msg['Subject'] = 'Application Error Report'
msg['From'] = '[email protected]'
msg['To'] = '[email protected]'
# Send the message via SMTP server
s = smtplib.SMTP('localhost')
s.send_message(msg)
s.quit()
def global_exception_handler(exctype, value, tb):
error_details = ''.join(traceback.format_exception(exctype, value, tb))
send_error_to_developer(error_details)
# Optionally, inform the user that an error occurred
import sys
sys.excepthook = global_exception_handler
# Your application code here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment