c#中所有异常都不强制try/catch吗? 这样其实并不方便哦。我都不知道哪些方法会抛异常,一个一个查肯定不现实~像java那样不try/catch异常就会报错,反而增加了程序的健壮性~~求解~~各位是怎么处理异常的?一个try/catch包住全部语句? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 仅处理你能处理的异常。捕获你不能处理的异常,并把它吞掉(不显示给用户),是有害的,它使程序内部数据处于无效的状态。所以宁可抛异常挂掉,也不要吞异常。在调用一个方法的使用,不用特意去看会有什么异常。仅当你意识到可能有问题时,才去MSDN看会抛什么异常,选择你能用程序恢复的异常来捕获。一般网络、IO等很可能会出错,这要注意一下异常。 如果你真的想捕获所有的异常,让无效数据在程序内部存在着,有一个位置可以满足你。 [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); Application.ThreadException += Application_ThreadException; } static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e) { throw new NotImplementedException(); } 如果你真的要捕获所有的异常,让无效数据在应用程序内存在着,有一个位置可以满足你。 [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new Form1()); Application.ThreadException += Application_ThreadException; } static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e) { throw new NotImplementedException(); } 在需要try/catch时才用,比如读文件时,读数据库时,这样方便给客户显示出出错的原因。其它时间不需要。 强制处理异常会很麻烦,这是我讨厌java的地方,c#中内部没有处理的异常,我会在最上层用一个try包住,然后把异常信息写入日志文件, 强制处理异常会很麻烦,这是我讨厌java的地方,c#中内部没有处理的异常,我会在最上层用一个try包住,然后把异常信息写入日志文件, 急,Timer组件的Tick事件执行导致程序很卡 导出的excel文档中 单元格Cells[2, 1] 显示“System.__ComObject1”? 请问:如何用JS获取GridView模板列里文本框的值 lock(x)?X是啥意思??? 组合键的问题ALT+E 控件事件问题? asp.net mvc 验证问题 代码头部有using tw.xx.xxx.xxxx。我怎么才能查找此命名空间? 如何在dataGird中选中一行后进行删除 Base-64 字符串中的无效字符 连接wcf服务错误 关于WMS系统中货位与货物关系设计的疑问
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1()); Application.ThreadException += Application_ThreadException;
} static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
{
throw new NotImplementedException();
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1()); Application.ThreadException += Application_ThreadException;
} static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
{
throw new NotImplementedException();
}