[.net]捕获错误机制
2014-01-05 11:31
316 查看
一般获取错误用TryCatch即可,但有时候,有的却捕获不到,程序就异常奔溃,经过@灰太龙的指导,发现这段代码可行,能够捕获异常,就算不用trycatch也行。
static Program()
{
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
}
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
string strException = string.Format("{0}发生系统异常。\r\n{1}\r\n\r\n\r\n", DateTime.Now, e.ExceptionObject.ToString());
File.AppendAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SystemException.log"), strException);
}
static Program()
{
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
}
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
string strException = string.Format("{0}发生系统异常。\r\n{1}\r\n\r\n\r\n", DateTime.Now, e.ExceptionObject.ToString());
File.AppendAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "SystemException.log"), strException);
}
相关文章推荐
- 缓存应用:单例模式在缓存机制中的应用
- UVa 10161 Ant on a Chessboard
- Hibernate映射解析——七种映射关系
- The following processes: -cmd.exe -java.exe are locking the following directory:
- Qt网络(二)HTTP编程
- ubuntu12.04开机黑屏解决方法
- Easyui1.32源码+API翻译全篇导航
- checkdsk u盘无法读取
- Linux的用户组管理
- 学习笔记-轻量级Java EE:模式--命令模式
- 分享一个NHibernate的博客链接
- Visual Stdio 2010使用NUnit
- Linux的用户管理
- MapReduce的input为SequenceFile的相关实验
- nagios快速部署
- 学习鸟哥的Linux私房菜笔记(2)——基础指令
- 学习鸟哥的Linux私房菜笔记(2)——基础指令
- 标准I/O库之每次一行I/O
- 电子商务王闯教你找回QQ原来手机图标
- ZOL上,下载的这个嵌入版本如何使用