| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1308 人关注过本帖
标题:求助::处理异常中的catch语句总是不执行
只看楼主 加入收藏
ann55
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2005-4-6
收藏
 问题点数:0 回复次数:3 
求助::处理异常中的catch语句总是不执行

请大家帮忙 我的处理异常执行不了 private void menuOpenFile_Click(object sender, System.EventArgs e) { //定义变量来保存对话框选择的结果 System.Windows.Forms.DialogResult yzResult; string yzmsg; string m_strFileName=""; string m_strTemp=""; m_statusBar.Text="正在打开文件"; if(m_richTextBox.Text!="") { //如果对话框中有文本 if(ModifiedFlag==true) { //如果文本被修改过 就提示是否保存文本 yzmsg="文件"+FileName+"是否保存该文件?\n"; yzResult=MessageBox.Show(this,yzmsg,"小小写字板",System.Windows.Forms.MessageBoxButtons.YesNoCancel,System.Windows.Forms.MessageBoxIcon.Exclamation,System.Windows.Forms.MessageBoxDefaultButton.Button2); if(yzResult==DialogResult.Yes) { //如果保存的对话框选择的结果是 yes 则保存文件 if(IsSavedFlag==true) { //如果已经保存过了 调用保存文件菜单的PreformClick方法 menuSaveFile.PerformClick();

} else { //如果还没有保存 调用另存为文件菜单的performClick方法 menuSaveAs.PerformClick();

} if(yzResult==DialogResult.Cancel) { //如果保存对话框选择的是cancel return; } }

} m_OpenFile.Filter="文本文件(*.txt)|*.txt"; m_OpenFile.FileName="";//初始化文件名变量 //弹出打开文件对话框 if(m_OpenFile.ShowDialog()==DialogResult.OK||m_OpenFile.FileName.Length>0) //[][],.,.,.<><><><><><><><><> m_OpenFile.FileName.Length>=0 m_OpenFile.FileName.Length>=0 { //如果选择了要打开的文件,且点击了打开按纽 m_strFileName=m_OpenFile.FileName; FileName=m_strFileName; } else { return; } m_richTextBox.Text="";//清空文本框 FileStream m_FileStream=null; //声明一个文件流 string m_strFileContents=""; m_strOriginText=""; if(m_strFileName!="") { //如果选择了要打开的文件 try { m_strTemp=""; int m_GetByte=1; //创建一个FileStream类的对象 m_FileStream m_FileStream=new FileStream(m_strFileName,FileMode.Open,FileAccess.Read); Byte[] m_Byte=new Byte[1024]; m_Byte.Initialize();//初始化一个数组 for(;m_GetByte!=0;) { //按字节读文字 System.Text.Encoding encoding=System.Text.Encoding.UTF8; m_Byte.Initialize(); m_strTemp=""; m_GetByte=m_FileStream.Read(m_Byte,0,1024); m_strTemp=encoding.GetString(m_Byte,0,1024); m_strFileContents+=m_strTemp; //把结果保存在m_strFileContents } } catch(FileNotFoundException e1) { //捕获错误 Console.WriteLine(e1); string m_strmgs="文件没有找到:"+ e1; System.Windows.Forms.MessageBox.Show(this,m_strmgs,"小小写字板",System.Windows.Forms.MessageBoxButtons.OK,System.Windows.Forms.MessageBoxIcon.Question); return; } finally { if(m_FileStream!=null) { m_FileStream.Close(); } } 就是catch语句 怎么着就是不执行 我都要郁闷死了 请各位高手指点

搜索更多相关主题的帖子: catch 语句 string 对话框 
2005-04-06 11:40
nyzfl
Rank: 1
等 级:新手上路
帖 子:278
专家分:0
注 册:2005-3-21
收藏
得分:0 
说的明白点

My-Blog地址:http://fenglin.
2005-04-06 11:45
幻风幻云
Rank: 1
等 级:新手上路
帖 子:762
专家分:0
注 册:2005-1-14
收藏
得分:0 
FileNotFoundException 没有定义吧

2005-04-06 11:51
yushengou
Rank: 1
等 级:新手上路
帖 子:401
专家分:0
注 册:2005-3-30
收藏
得分:0 
把catch(FileNotFoundException e1)改为
catch(Exception e1)试试

我是初学者,希望大家能多多帮助我 /bbs/showimg.asp?BoardID=34&filename=2005-4/200542294030151.gif" border="0" onload="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onmouseover="if(this.width>screen.width*0.7) {this.resized=true; this.width=screen.width*0.7; this.style.cursor='hand'; this.alt='Click here to open new window\nCTRL+Mouse wheel to zoom in/out';}" onclick="if(!this.resized) {return true;} else {window.open('http://bbs./bbs/showimg.asp?BoardID=34&filename=2005-4/200542294030151.gif');}" onmousewheel="return imgzoom(this);" alt="" />
2005-04-06 12:32
快速回复:求助::处理异常中的catch语句总是不执行
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017827 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved