请帮我尝试&捕获块 [英] Pls help me for my try & catch block

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

问题描述

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

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

推荐答案

阅读此文章

希望您能获得有关try catch的完整信息

使用Try ... Catch ...,最后! [
read this articale

i hope you will get full information about try catch

Using Try... Catch..., Finally![^]


根据您的要求创建自定义例外.

检查以下有关如何创建自定义异常的链接.
第一 [第二 [第三 [
Create Custom Exceptions as per your requirements.

Check below links on how to create custom exceptions.
First[^]

Second[^]

Third[^]


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;
}


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

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