C#抛出异常后处理问题 其实就是想要把系统的错误提示框,变成MESSAGEBOX的,messagebox的确定按钮没有其他用处,就是确认错误信息,然后让程序停留在原界面不往下执行。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 try{...........}catch{//这里处理过异常就不要再抛出来了//比如MessageBox.Show(ex.Message);} *****************************************************************************签名档: http://feiyun0112.cnblogs.com/ try { int i = Convert.ToInt32("te"); } catch (Exception ex) { MessageBox.Show(ex.Message); } try { int i = Convert.ToInt32("te"); } catch (Exception ex) { MessageBox.Show(ex.Message); } #region 添加xml列表,将数据转换成XML格式并且存到字典表中 public string AddXmlList(string sid) { XmlDocument xml = new XmlDocument(); XmlDeclaration xmldecl; xmldecl = xml.CreateXmlDeclaration("1.0", "UTF-8", null); xml.AppendChild(xmldecl); XmlNode root = xml.CreateNode(XmlNodeType.Element, "root", null); xml.AppendChild(root); root = xml.SelectSingleNode("/root"); XmlNode node_head = xml.CreateNode(XmlNodeType.Element, "head", null); root.AppendChild(node_head); XmlElement head_login = xml.CreateElement("login"); head_login.SetAttribute("key", "KEY"); head_login.SetAttribute("pwd", "123456"); head_login.SetAttribute("usr", "llyb_jm_zyxrmyy"); node_head.AppendChild(head_login); XmlElement head_service = xml.CreateElement("service"); head_service.SetAttribute("digest", ""); head_service.SetAttribute("sid", sid); node_head.AppendChild(head_service); XmlNode node_body = xml.CreateNode(XmlNodeType.Element, "body", null); root.AppendChild(node_body); XmlNode request = xml.CreateNode(XmlNodeType.Element, "request", null); node_body.AppendChild(request); XmlNode node_data = xml.CreateNode(XmlNodeType.Element,"data",null); XmlElement param_content = xml.CreateElement("param"); foreach (var item in dictInParaList) { param_content.SetAttribute(item.Key, item.Value); node_data.AppendChild(param_content); } //XmlElement node_data = xml.CreateElement("data"); if (dtRe != null) { for (int i = 0; i < dtRe.Rows.Count; i++) { XmlElement data_row = xml.CreateElement("row"); for (int j = 0; j < dtRe.Columns.Count; j++) { data_row.SetAttribute(dtRe.Columns[j].ColumnName, dtRe.Rows[i][j].ToString()); } node_data.AppendChild(data_row); } } request.AppendChild(node_data); return xml.InnerXml.ToString(); } #endregion #region 上传已经按照格式生成好的数据,并且解析返回的结果存到字典表中 /// <summary> /// 业务处理 /// </summary> /// <param name="MethodName">方法名</param> /// <param name="ObjList">参数列表</param> public void ExeMehodReObj(string ReXml) { try { XmlDocument ReResulst = new XmlDocument(); string result = Upload.execute(ReXml); //进行医保业务 ReResulst.LoadXml(result); //读取医保返回结果 XmlNode xmlMeassage = ReResulst.SelectSingleNode("/root/body/response/data/row"); //截取row节点 XmlElement xee = (XmlElement)xmlMeassage; //将节点转换为xml元素 //if (!xee.Attributes["errorMSG"].Value.ToString().Contains("未找到住院明细信息")) if (xee.Attributes["status"].Value.ToString() != "0") { if (!xee.Attributes["errorMSG"].Value.ToString().Contains("未找到住院明细信息")) //判断元素中的status属性值,0成功,其他失败 { throw new Exception("医保返回错误:" + xee.Attributes["errorMSG"].Value.ToString()); //取出错误信息 } } XmlNode Result = ReResulst.SelectSingleNode("/root/body/response/data/row"); //截取row节点 XmlElement xe = (XmlElement)Result; //将节点转换为xml元素 dictReInPara = new Dictionary<string, string>(); //将元素中的所有返回值保存在dictionary列表中 for (int i = 0; i < xe.Attributes.Count; i++) { dictReInPara.Add(xe.Attributes[i].Name, xe.Attributes[i].Value); } } catch (System.Exception ex) { //throw ex; MessageBox.Show(ex.Message.ToString()); } }/////////////////////////////////////////////if (djidh == "") { dictInParaList.Add("aac161", T_CARDNUM.Text); //卡号 dictInParaList.Add("aac162", T_CARDPWD.Text); //密码 dictInParaList.Add("aae030", dateTimePicker1.Value.ToString("yyyyMMdd")); //入院时间 dictInParaList.Add("abc018", "ABC018#############1"); //是否允许联网结算 dictInParaList.Add("aaz164", T_BZCODE.Text); //病种 ExeMehodReObj(AddXmlList("save_hos_apply")); zyid = dictReInPara["pk_kc41"].ToString(); //住院申请的主键,按照版主说的,提示框是变了,但是他还会执行这一句,如果返回的参数没有这个值得话,就回报错。}版主,按照你说的,提示框是变了,我点了messagebox的确定按钮后,还是会执行代码中的那个获取参数值得语句。还会报错,因为前面的入参由于种种原因如果失败了,那获取住院申请ID的出参就没有了。所以我想早弹出异常后,点击确定,下面就不执行了。 #region 添加xml列表,将数据转换成XML格式并且存到字典表中 public string AddXmlList(string sid) { XmlDocument xml = new XmlDocument(); XmlDeclaration xmldecl; xmldecl = xml.CreateXmlDeclaration("1.0", "UTF-8", null); xml.AppendChild(xmldecl); XmlNode root = xml.CreateNode(XmlNodeType.Element, "root", null); xml.AppendChild(root); root = xml.SelectSingleNode("/root"); XmlNode node_head = xml.CreateNode(XmlNodeType.Element, "head", null); root.AppendChild(node_head); XmlElement head_login = xml.CreateElement("login"); head_login.SetAttribute("key", "KEY"); head_login.SetAttribute("pwd", "123456"); head_login.SetAttribute("usr", "llyb_jm_zyxrmyy"); node_head.AppendChild(head_login); XmlElement head_service = xml.CreateElement("service"); head_service.SetAttribute("digest", ""); head_service.SetAttribute("sid", sid); node_head.AppendChild(head_service); XmlNode node_body = xml.CreateNode(XmlNodeType.Element, "body", null); root.AppendChild(node_body); XmlNode request = xml.CreateNode(XmlNodeType.Element, "request", null); node_body.AppendChild(request); XmlNode node_data = xml.CreateNode(XmlNodeType.Element,"data",null); XmlElement param_content = xml.CreateElement("param"); foreach (var item in dictInParaList) { param_content.SetAttribute(item.Key, item.Value); node_data.AppendChild(param_content); } //XmlElement node_data = xml.CreateElement("data"); if (dtRe != null) { for (int i = 0; i < dtRe.Rows.Count; i++) { XmlElement data_row = xml.CreateElement("row"); for (int j = 0; j < dtRe.Columns.Count; j++) { data_row.SetAttribute(dtRe.Columns[j].ColumnName, dtRe.Rows[i][j].ToString()); } node_data.AppendChild(data_row); } } request.AppendChild(node_data); return xml.InnerXml.ToString(); } #endregion #region 上传已经按照格式生成好的数据,并且解析返回的结果存到字典表中 /// <summary> /// 业务处理 /// </summary> /// <param name="MethodName">方法名</param> /// <param name="ObjList">参数列表</param> public void ExeMehodReObj(string ReXml) { try { XmlDocument ReResulst = new XmlDocument(); string result = Upload.execute(ReXml); //进行医保业务 ReResulst.LoadXml(result); //读取医保返回结果 XmlNode xmlMeassage = ReResulst.SelectSingleNode("/root/body/response/data/row"); //截取row节点 XmlElement xee = (XmlElement)xmlMeassage; //将节点转换为xml元素 //if (!xee.Attributes["errorMSG"].Value.ToString().Contains("未找到住院明细信息")) if (xee.Attributes["status"].Value.ToString() != "0") { if (!xee.Attributes["errorMSG"].Value.ToString().Contains("未找到住院明细信息")) //判断元素中的status属性值,0成功,其他失败 { throw new Exception("医保返回错误:" + xee.Attributes["errorMSG"].Value.ToString()); //取出错误信息 } } XmlNode Result = ReResulst.SelectSingleNode("/root/body/response/data/row"); //截取row节点 XmlElement xe = (XmlElement)Result; //将节点转换为xml元素 dictReInPara = new Dictionary<string, string>(); //将元素中的所有返回值保存在dictionary列表中 for (int i = 0; i < xe.Attributes.Count; i++) { dictReInPara.Add(xe.Attributes[i].Name, xe.Attributes[i].Value); } } catch (System.Exception ex) { //throw ex; MessageBox.Show(ex.Message.ToString()); } }/////////////////////////////////////////////if (djidh == "") { dictInParaList.Add("aac161", T_CARDNUM.Text); //卡号 dictInParaList.Add("aac162", T_CARDPWD.Text); //密码 dictInParaList.Add("aae030", dateTimePicker1.Value.ToString("yyyyMMdd")); //入院时间 dictInParaList.Add("abc018", "ABC018#############1"); //是否允许联网结算 dictInParaList.Add("aaz164", T_BZCODE.Text); //病种 ExeMehodReObj(AddXmlList("save_hos_apply")); zyid = dictReInPara["pk_kc41"].ToString(); //住院申请的主键,按照版主说的,提示框是变了,但是他还会执行这一句,如果返回的参数没有这个值得话,就回报错。}版主,按照你说的,提示框是变了,我点了messagebox的确定按钮后,还是会执行代码中的那个获取参数值得语句。还会报错,因为前面的入参由于种种原因如果失败了,那获取住院申请ID的出参就没有了。所以我想早弹出异常后,点击确定,下面就不执行了。你这个是一个函数,既然你的这个函数会可能失败,建议你最好就不要用void作为返回值。建议可以返回一个bool,然后你可以在catch块内进行一个false的返回,告诉调用者执行失败。而你在进行return的时候,函数自己就退出了,不会往下走了。希望对你有帮助。 VB写入文件 combobox 选定的问题 .net来路是怎么判断的呢??? byte[]操作问题 赋值 与 查找 使用SQLDMO还原数据库时,如何更改MDF和LDF的物理文件路径? 請幫忙把這一段翻譯成c++好嗎? 怎样才能看到执行结果 数据合并显示问题 C# 数组问题 richtextbox控件内容的格式 C# 非正常事件的捕捉 grid分页如何做
{
...........
}
catch
{//这里处理过异常就不要再抛出来了
//比如
MessageBox.Show(ex.Message);
}
*****************************************************************************
签名档: http://feiyun0112.cnblogs.com/
{
int i = Convert.ToInt32("te");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
{
int i = Convert.ToInt32("te");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
public string AddXmlList(string sid)
{
XmlDocument xml = new XmlDocument();
XmlDeclaration xmldecl;
xmldecl = xml.CreateXmlDeclaration("1.0", "UTF-8", null);
xml.AppendChild(xmldecl);
XmlNode root = xml.CreateNode(XmlNodeType.Element, "root", null);
xml.AppendChild(root);
root = xml.SelectSingleNode("/root");
XmlNode node_head = xml.CreateNode(XmlNodeType.Element, "head", null);
root.AppendChild(node_head);
XmlElement head_login = xml.CreateElement("login");
head_login.SetAttribute("key", "KEY");
head_login.SetAttribute("pwd", "123456");
head_login.SetAttribute("usr", "llyb_jm_zyxrmyy");
node_head.AppendChild(head_login);
XmlElement head_service = xml.CreateElement("service");
head_service.SetAttribute("digest", "");
head_service.SetAttribute("sid", sid);
node_head.AppendChild(head_service);
XmlNode node_body = xml.CreateNode(XmlNodeType.Element, "body", null);
root.AppendChild(node_body);
XmlNode request = xml.CreateNode(XmlNodeType.Element, "request", null);
node_body.AppendChild(request);
XmlNode node_data = xml.CreateNode(XmlNodeType.Element,"data",null);
XmlElement param_content = xml.CreateElement("param");
foreach (var item in dictInParaList)
{
param_content.SetAttribute(item.Key, item.Value);
node_data.AppendChild(param_content);
}
//XmlElement node_data = xml.CreateElement("data"); if (dtRe != null)
{
for (int i = 0; i < dtRe.Rows.Count; i++)
{
XmlElement data_row = xml.CreateElement("row");
for (int j = 0; j < dtRe.Columns.Count; j++)
{
data_row.SetAttribute(dtRe.Columns[j].ColumnName, dtRe.Rows[i][j].ToString());
}
node_data.AppendChild(data_row);
}
}
request.AppendChild(node_data);
return xml.InnerXml.ToString(); }
#endregion
#region 上传已经按照格式生成好的数据,并且解析返回的结果存到字典表中
/// <summary>
/// 业务处理
/// </summary>
/// <param name="MethodName">方法名</param>
/// <param name="ObjList">参数列表</param>
public void ExeMehodReObj(string ReXml)
{
try
{
XmlDocument ReResulst = new XmlDocument();
string result = Upload.execute(ReXml); //进行医保业务
ReResulst.LoadXml(result); //读取医保返回结果
XmlNode xmlMeassage = ReResulst.SelectSingleNode("/root/body/response/data/row"); //截取row节点
XmlElement xee = (XmlElement)xmlMeassage; //将节点转换为xml元素
//if (!xee.Attributes["errorMSG"].Value.ToString().Contains("未找到住院明细信息"))
if (xee.Attributes["status"].Value.ToString() != "0")
{
if (!xee.Attributes["errorMSG"].Value.ToString().Contains("未找到住院明细信息")) //判断元素中的status属性值,0成功,其他失败
{
throw new Exception("医保返回错误:" + xee.Attributes["errorMSG"].Value.ToString()); //取出错误信息
} } XmlNode Result = ReResulst.SelectSingleNode("/root/body/response/data/row"); //截取row节点
XmlElement xe = (XmlElement)Result; //将节点转换为xml元素
dictReInPara = new Dictionary<string, string>(); //将元素中的所有返回值保存在dictionary列表中
for (int i = 0; i < xe.Attributes.Count; i++)
{
dictReInPara.Add(xe.Attributes[i].Name, xe.Attributes[i].Value);
}
}
catch (System.Exception ex)
{
//throw ex;
MessageBox.Show(ex.Message.ToString());
}
}
/////////////////////////////////////////////
if (djidh == "")
{
dictInParaList.Add("aac161", T_CARDNUM.Text); //卡号
dictInParaList.Add("aac162", T_CARDPWD.Text); //密码
dictInParaList.Add("aae030", dateTimePicker1.Value.ToString("yyyyMMdd")); //入院时间
dictInParaList.Add("abc018", "ABC018#############1"); //是否允许联网结算
dictInParaList.Add("aaz164", T_BZCODE.Text); //病种
ExeMehodReObj(AddXmlList("save_hos_apply"));
zyid = dictReInPara["pk_kc41"].ToString(); //住院申请的主键,按照版主说的,提示框是变了,但是他还会执行这一句,如果返回的参数没有这个值得话,就回报错。
}版主,按照你说的,提示框是变了,我点了messagebox的确定按钮后,还是会执行代码中的那个获取参数值得语句。还会报错,因为前面的入参由于种种原因如果失败了,那获取住院申请ID的出参就没有了。所以我想早弹出异常后,点击确定,下面就不执行了。
public string AddXmlList(string sid)
{
XmlDocument xml = new XmlDocument();
XmlDeclaration xmldecl;
xmldecl = xml.CreateXmlDeclaration("1.0", "UTF-8", null);
xml.AppendChild(xmldecl);
XmlNode root = xml.CreateNode(XmlNodeType.Element, "root", null);
xml.AppendChild(root);
root = xml.SelectSingleNode("/root");
XmlNode node_head = xml.CreateNode(XmlNodeType.Element, "head", null);
root.AppendChild(node_head);
XmlElement head_login = xml.CreateElement("login");
head_login.SetAttribute("key", "KEY");
head_login.SetAttribute("pwd", "123456");
head_login.SetAttribute("usr", "llyb_jm_zyxrmyy");
node_head.AppendChild(head_login);
XmlElement head_service = xml.CreateElement("service");
head_service.SetAttribute("digest", "");
head_service.SetAttribute("sid", sid);
node_head.AppendChild(head_service);
XmlNode node_body = xml.CreateNode(XmlNodeType.Element, "body", null);
root.AppendChild(node_body);
XmlNode request = xml.CreateNode(XmlNodeType.Element, "request", null);
node_body.AppendChild(request);
XmlNode node_data = xml.CreateNode(XmlNodeType.Element,"data",null);
XmlElement param_content = xml.CreateElement("param");
foreach (var item in dictInParaList)
{
param_content.SetAttribute(item.Key, item.Value);
node_data.AppendChild(param_content);
}
//XmlElement node_data = xml.CreateElement("data"); if (dtRe != null)
{
for (int i = 0; i < dtRe.Rows.Count; i++)
{
XmlElement data_row = xml.CreateElement("row");
for (int j = 0; j < dtRe.Columns.Count; j++)
{
data_row.SetAttribute(dtRe.Columns[j].ColumnName, dtRe.Rows[i][j].ToString());
}
node_data.AppendChild(data_row);
}
}
request.AppendChild(node_data);
return xml.InnerXml.ToString(); }
#endregion
#region 上传已经按照格式生成好的数据,并且解析返回的结果存到字典表中
/// <summary>
/// 业务处理
/// </summary>
/// <param name="MethodName">方法名</param>
/// <param name="ObjList">参数列表</param>
public void ExeMehodReObj(string ReXml)
{
try
{
XmlDocument ReResulst = new XmlDocument();
string result = Upload.execute(ReXml); //进行医保业务
ReResulst.LoadXml(result); //读取医保返回结果
XmlNode xmlMeassage = ReResulst.SelectSingleNode("/root/body/response/data/row"); //截取row节点
XmlElement xee = (XmlElement)xmlMeassage; //将节点转换为xml元素
//if (!xee.Attributes["errorMSG"].Value.ToString().Contains("未找到住院明细信息"))
if (xee.Attributes["status"].Value.ToString() != "0")
{
if (!xee.Attributes["errorMSG"].Value.ToString().Contains("未找到住院明细信息")) //判断元素中的status属性值,0成功,其他失败
{
throw new Exception("医保返回错误:" + xee.Attributes["errorMSG"].Value.ToString()); //取出错误信息
} } XmlNode Result = ReResulst.SelectSingleNode("/root/body/response/data/row"); //截取row节点
XmlElement xe = (XmlElement)Result; //将节点转换为xml元素
dictReInPara = new Dictionary<string, string>(); //将元素中的所有返回值保存在dictionary列表中
for (int i = 0; i < xe.Attributes.Count; i++)
{
dictReInPara.Add(xe.Attributes[i].Name, xe.Attributes[i].Value);
}
}
catch (System.Exception ex)
{
//throw ex;
MessageBox.Show(ex.Message.ToString());
}
}
/////////////////////////////////////////////
if (djidh == "")
{
dictInParaList.Add("aac161", T_CARDNUM.Text); //卡号
dictInParaList.Add("aac162", T_CARDPWD.Text); //密码
dictInParaList.Add("aae030", dateTimePicker1.Value.ToString("yyyyMMdd")); //入院时间
dictInParaList.Add("abc018", "ABC018#############1"); //是否允许联网结算
dictInParaList.Add("aaz164", T_BZCODE.Text); //病种
ExeMehodReObj(AddXmlList("save_hos_apply"));
zyid = dictReInPara["pk_kc41"].ToString(); //住院申请的主键,按照版主说的,提示框是变了,但是他还会执行这一句,如果返回的参数没有这个值得话,就回报错。
}版主,按照你说的,提示框是变了,我点了messagebox的确定按钮后,还是会执行代码中的那个获取参数值得语句。还会报错,因为前面的入参由于种种原因如果失败了,那获取住院申请ID的出参就没有了。所以我想早弹出异常后,点击确定,下面就不执行了。你这个是一个函数,既然你的这个函数会可能失败,建议你最好就不要用void作为返回值。
建议可以返回一个bool,然后你可以在catch块内进行一个false的返回,告诉调用者执行失败。
而你在进行return的时候,函数自己就退出了,不会往下走了。
希望对你有帮助。