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.

Revisions

  1. tschreiner created this gist Jan 22, 2024.
    24 changes: 24 additions & 0 deletions exception_handler.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    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