异常捕获 [英] exception catching

查看:96
本文介绍了异常捕获的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友,

我正在用简单的说明来修改我的问题

我正在创建一个网站,在我的数据库中,我有一个表,其中的一列是唯一标识符.因此,从网页上每当我在该列中插入重复值时,都会在数据访问层中引发异常.因此,我想在我的Web表单中捕获此异常,也希望将错误消息显示为无法插入重复的值".在网页中.


问候,
srikar

Dear Friends,

i am modifying my question with simple description

I am creating a website, in my database i have a table in which one of the column is unique identifier. So from webpage when ever i am inserting duplicate values in that column its throwing an exception in Data access Layer. so i want to catch this exception in my web form as well as i want to display the error message as "can not insert duplicate values." in the webpage.


Regards,
srikar

推荐答案

对不起,您的问题是什么?您所描述的内容还不清楚.请更新您的问题以使其更清楚,确保准确描述您所遇到的问题以及实际问题是什么.
I''m sorry, what''s your question? What you have described is a little unclear. Please update your question to make it more clear, making sure to describe exactly the problem you are having and what your actual question is.


在代码中捕获异常(VB?C#?)使用try/catch块.然后将标签的文本设置为不能插入重复的值".
Catch the exception in your code (VB? C#?) using a try/catch block. Then set the text of a label to "Cannot insert duplicate values".


try <br />
{<br />
<br />
   /// do your insert here<br />
<br />
}<br />
catch (Exception ex)<br />
{<br />
   // set the friendly error here:<br />
   lbError.Text = " ... no duplicates";<br />
   return;<br />
<br />
}


这篇关于异常捕获的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆