三层异常处理 [英] Three tier exception handling
问题描述
大家好,
任何人都可以帮我处理三层架构中的异常处理,
对于一个实例
我有价值从UI并发送到中间层,其中验证值,如果验证失败,则抛出异常。
如何向特定页面显示该异常,并显示错误消息。
问题实例
UI(invoiceUI.aspx)
Hello All ,
Can any one help me with Exception Handling in three Tier Architecture,
For An instance
I am taking value from UI and sending to Middle tier where the value is validated and if validation fails it throws a exception.
How can i show that exception to a particular page with error message.
Instance of problem
UI(invoiceUI.aspx)
protected void Button1_Click(object sender, EventArgs e)
{
invoice objinvoice = new invoice();
getdata(objinvoice);
}
public void getdata(invoice objinvoice)
{
objinvoice.fname = fname.Text;
}
中间层(invoice.cs)>
Middle Tier (invoice.cs)
private string _fname;
public string fname
{
set
{
if (value.Length == 0)
{
throw new Exception("Please Enter the Valid Name");
}
_fname = value;
}
get
{
return _fname;
}
}
怎么做,请帮助。
我尝试了什么:
i试图在UI中获取异常
how to do this , help is appreciated.
What I have tried:
i have tried putting to get the exception in UI which do not work
推荐答案
你的代码会变成这样的:
Your code would become something like this:
public void getdata(invoice objinvoice)
{
try {
objinvoice.fname = fname.Text;
} catch (Exception ex) {
lblMessage.Text = ex.Message;
}
}
lblMessage
是一个标签控制,您可以用几乎任何可以显示文本的东西替换它。
lblMessage
is a Label control, you can replace it with pretty much anything that can display text.
这篇关于三层异常处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!