winform-全局异常捕获作用
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using JxsFL.CaiGou;
using JxsFL.CangKu;
using JxsFL.CangKu.Out;
using JxsFL.KJ;
using JxsFL.LEDs;
using DevExpress.LookAndFeel;
using System.IO;
namespace JxsFL
{
static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
try
{
//处理未捕获的异常
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);
//处理UI线程异常
Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
//处理非UI线程异常
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
if (System.Diagnostics.Process.GetProcessesByName(System.Diagnostics.Process.GetCurrentProcess().ProcessName).Length > 1)
{
MessageBox.Show("已经有一个运行了");
}
else
{
DevExpress.UserSkins.BonusSkins.Register();
DevExpress.UserSkins.OfficeSkins.Register();
DevExpress.Skins.SkinManager.EnableFormSkins();
UserLookAndFeel.Default.SetSkinStyle("Office 2010 Blue");
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
//Application.Run(new JxsFL.Mead.ShiFuDCL.ShiFuDCLFind());
Application.Run(new Login());
}
}
catch (Exception ex)
{
string str = "";
string strDateInfo = "出现应用程序未处理的异常:" + DateTime.Now.ToString() + "\r\n";
if (ex != null)
{
str = string.Format(strDateInfo + "异常类型:{0}\r\n异常消息:{1}\r\n异常信息:{2}\r\n",
ex.GetType().Name, ex.Message, ex.StackTrace);
}
else
{
str = string.Format("应用程序线程错误:{0}", ex);
}
writeLog(str);
MessageBox.Show("发生致命错误,请及时联系深圳市金佳诺软件科技技术支持!", "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
/// <summary>
///发生异常写入文本文件,并弹出提示框(自定义,比如上传给邮件等) /// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
{
string str = "";
string strDateInfo = "出现应用程序未处理的异常:" + DateTime.Now.ToString() + "\r\n";
Exception error = e.Exception as Exception;
if (error != null)
{
str = string.Format(strDateInfo + "异常类型:{0}\r\n异常消息:{1}\r\n异常信息:{2}\r\n",
error.GetType().Name, error.Message, error.StackTrace);
}
else
{
str = string.Format("应用程序线程错误:{0}", e);
}
writeLog(str);
MessageBox.Show("发生致命错误,请及时联系作者!", "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
string str = "";
Exception error = e.ExceptionObject as Exception;
string strDateInfo = "出现应用程序未处理的异常:" + DateTime.Now.ToString() + "\r\n";
if (error != null)
{
str = string.Format(strDateInfo + "Application UnhandledException:{0};\n\r堆栈信息:{1}", error.Message, error.StackTrace);
}
else
{
str = string.Format("Application UnhandledError:{0}", e);
}
writeLog(str);
MessageBox.Show("发生致命错误,请停止当前操作并及时联系作者!", "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
/// <summary>
/// 写文件
/// </summary>
/// <param name="str"></param>
static void writeLog(string str)
{
if (!Directory.Exists("ErrLog"))
{
Directory.CreateDirectory("ErrLog");
}
using (StreamWriter sw = new StreamWriter(@"ErrLog\ErrLog.txt", true))
{
sw.WriteLine(str);
sw.WriteLine("---------------------------------------------------------");
sw.Close();
}
}
}
}
winform-全局异常捕获作用的更多相关文章
- winform全局异常捕获
/// <summary> /// 应用程序的主入口点. /// </summary> public static ApplicationContext context; [S ...
- C#中的那些全局异常捕获
1.WPF全局捕获异常 public partial class App : Application { public App() { // 在异 ...
- 使用spring利用HandlerExceptionResolver实现全局异常捕获
最近一直没有时间更新是因为一直在更新自己使用的框架. 之后会慢慢带来对之前使用的spring+mvc+mybatis的优化. 会使用一些新的特性,实现一些新的功能. 我会尽量分离业务,封装好再拿出来. ...
- .Net下的全局异常捕获问题
全局异常捕获主要目标并不是为了将异常处理掉防止程序崩溃.因为当错误被你的全局异常捕获器抓到的时候,已经证实了你程序中存在BUG. 一般而言,我们的全局异常捕获主要作用就是接收到异常之后进行异常的反馈. ...
- (转)C#中的那些全局异常捕获
C#中的那些全局异常捕获(原文链接:http://www.cnblogs.com/taomylife/p/4528179.html) 1.WPF全局捕获异常 public partia ...
- springboot(二 如何访问静态资源和使用模板引擎,以及 全局异常捕获)
在我们开发Web应用的时候,需要引用大量的js.css.图片等静态资源. 默认配置 Spring Boot默认提供静态资源目录位置需置于classpath下,目录名需符合如下规则: /static / ...
- spring boot: GlobalDefaultExceptionHandler方法内的友好错误提示,全局异常捕获
spring boot: GlobalDefaultExceptionHandler方法内的友好错误提示,全局异常捕获 当你的某个控制器内的某个方法报错,基本上回显示出java错误代码,非常不友好,这 ...
- Configure、中间件与ErrorHandlingMiddleware全局异常捕获
一.Configure Startup.cs中的Configure方法主要是http处理管道配置.中间件和一些系统配置,其中 IApplicationBuilder: 定义一个类,该类提供配置应用程序 ...
- MVC 好记星不如烂笔头之 ---> 全局异常捕获以及ACTION捕获
public class BaseController : Controller { /// <summary> /// Called after the action method is ...
- atitit.js浏览器环境下的全局异常捕获
atitit.js浏览器环境下的全局异常捕获 window.onerror = function(errorMessage, scriptURI, lineNumber) { var s= JSON. ...
随机推荐
- 不同操作系统上屏蔽oracle的操作系统认证方式
windows系统上>如果不想用户通过操作系统验证方式登录,可以修改 sqlnet.ora文件,把 SQLNET.AUTHENTICATION_SERVICES=NTS 前面加#注释掉就可以了. ...
- PHP如何批量生成手机号-使用PHP 如何生成一组不重复的手机号码?
<?php //匹配手机号的正则表达式 #^(13[0-9]|14[47]|15[0-35-9]|17[6-8]|18[0-9])([0-9]{8})$# $arr = array( 130,1 ...
- Windows 10 error code 0x80072efd
访问windows 10 store出现如下图的错误: 如果你是宽带连接,删掉现在的连接,新建一个同样的宽带连接就OK了. 哎,这个问题导致我半个月没上去Windows Store,我还真以为微软有问 ...
- Oracle查询索引碎片及数据表空间使用情况
--检查索引碎片情况,只能对单个表进行分析. --需要注意块的大小.索引的pctfree的值的大小.rowid的长度的不同,根据不同的情况修改相应的值 select index_name, c.NMB ...
- Paxos一致性算法
分布式系统的整体思路:协调者与参与者 分布式系统中,每个节点可以知道自己在事务操作过程中是成功还是失败,但无法获取其他节点的操作结果,所以就不知道这个事务是否在所有机器上全都执行成功,所以需要引入一个 ...
- WebService---Android中访问WebService接口的方法
最近公司有个项目需要从Android平台访问WebService接口,实现向发布的函数传递对象.在网上找了一些资料,发现使用ksoap2可以调用WebService传递对象. 需要引入ksoap ...
- IRaster、IRasterlayer、IRasterdataset之间的转换
IRaster.IRasterlayer.IRasterdataset之间的转换 layer = axMapControl.get_Layer(0);//需要的栅格图层 IRasterLayer ra ...
- 直接解压msi文件
msiexec /a "F:\TDDownload\subversion-1.5.5.msi" /qb TARGETDIR="F:\TDDownload\subversi ...
- oracle字符集相关问题
整理自网络+实验 字符集介绍 影响Oracle数据库字符集最重要的参数是NLS_LANG参数. 它的格式如下: NLS_LANG = language_territory.charset NLS_L ...
- strong & weak
Here is a quick summary: A strong reference will keep the object it points to from being deallocated ...