本文介绍了请帮我尝试&捕获块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的开发人员,
这是我的基本尝试捕获块

Dear Developers,
This is my basic try and catch block

try
{
some code..
}
catch(exception ex)
{
label1.text=ex.Message;
}



它可以正常工作并显示相应的异常,但是按照我的要求
例如-违反UNIQUE KEY约束"unique_User".无法在对象"dbo.UserDetails"中插入重复的密钥.该语句已终止"
然后我想将自己的消息打印为用户名已存在"
如何获得这个..
任何答案将不胜感激...
Thanku



it works fine and display the respective exceptions, But as per my requirement
for Example-- "Violation of UNIQUE KEY constraint ''unique_User''. Cannot insert duplicate key in object ''dbo.UserDetails''. The statement has been terminated"
then i want to print my own message as"user name already exists"
How to obtain this..
Any answers ll be appreciated...
Thanku

推荐答案



u can have more than one Exception like one for IO another for SQL and so on .


try
{
some code..
}
catch(exception ex)
{
   label1.text=ex.Message;
}
catch(exception ex)
{
   label1.text=ex.Message;
}
catch(exception ex)
{
   label1.text=ex.Message;
}
catch(exception ex)
{
   label1.text=ex.Message;
}


这篇关于请帮我尝试&捕获块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 12:24