⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ysexceptionhandler.cs

📁 一个通用的数据库访问层
💻 CS
字号:
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
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -