【发布时间】:2011-07-17 23:35:15
【问题描述】:
每个人都在 C# 中使用Try-Catch。我知道。
例如;
static void Main()
{
string s = null; // For demonstration purposes.
try
{
ProcessString(s);
}
catch (Exception e)
{
Console.WriteLine("{0} Exception caught.", e);
}
}
}
一切正常。
但是如何为特定错误指定名称?
例如;
try
{
enter username;
enter E-Mail;
}
catch
{
}
- 如果用户名已经存在,
ErrorMessage-->(“用户名已经存在”) - 如果电子邮件已经存在,
ErrorMessage-->(“电子邮件正在使用”)
我如何在C# 中做到这一点?
最好的问候,
发声
【问题讨论】:
-
检查名称是否已存在不应引发异常 IMO。
-
这个注释是否意味着我们可以放心地忽略这个问题!
-
@Brian:如果在检查过程中出现问题,可能会发生这种情况,但是,这不是重点:P
标签: c# error-handling try-catch