Component File /Utils/YSExceptionHandler.cs (C#)
using System;  
using System.Threading;  
using System.Windows.Forms;  
  
namespace YariSoft.Exceptions  
{  
    public class YSExceptionHandler  
    {  
        #region Public functions  
        public void OnThreadException(object sender, ThreadExceptionEventArgs t)  
        {  
            DialogResult result = DialogResult.Cancel;  
            try {  
                string errorMsg = "Application error occurred!\n\n";  
                errorMsg += "Program has created error report that you may send to developers by mail.\nThis message contains only error information.\nDo you wish to send this report?";  
                if( YariSoft.Utils.YMessages.Show(errorMsg, "Application Error", MessageBoxButtons.YesNo, MessageBoxIcon.Error )  
                    == DialogResult.Yes ){  
                    this.SendMail(t.Exception);  
                } else {  
                    YariSoft.Utils.YMessages.Show( t.Exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error );  
                }  
            } catch {  
                result = YariSoft.Utils.YMessages.Show( "Fatal Error", "Application Error", MessageBoxButtons.AbortRetryIgnore, MessageBoxIcon.Stop);  
            }  
  
            if (result == DialogResult.Abort) {  
                Application.Exit();  
            }  
        }  
        #endregion  
          
        #region Private functions  
        private void SendMail(Exception e)  
        {  
            int result = 0;  
            try{  
                string address    = "emalkov@zahav.net.il";  
                string subject    = Application.ProductName + " error report.";  
                string body        = "Date & Time: " + DateTime.Now.ToString() + "\n";  
                    body       += "Country: " + Application.CurrentCulture.EnglishName + "\n";  
                    body       += "Version: " + Application.ProductVersion + "\n";  
                    body       += "Stack Trace:\n" + e.StackTrace;  
                result = YariSoft.Utils.Mapi.Send( address, subject, body, true );  
            }catch( Exception E ){  
                YariSoft.Utils.YMessages.Show(E.Message + "(" + result.ToString() + ")", "Send Mail", MessageBoxButtons.OK, MessageBoxIcon.Stop);  
            }  
        }  
        #endregion  
    }  
}