Cant get the catch statement to catch the custom exception
Posted
by user282807
on Stack Overflow
See other posts from Stack Overflow
or by user282807
Published on 2010-03-12T02:30:02Z
Indexed on
2010/03/12
2:37 UTC
Read the original article
Hit count: 346
.NET
i have created a custom exception in the business layer and also using wcf layer where I am calling the methods in the business layer then in another website i am calling the method from wcf. i can see the message that i wrote in custom exception but the program goes staright to exception (the second catch block) instead of hitting my first catch block(where the custom exception is) when i hover over the exception i see my message but it's inside something called faultexception which i am not familiar with. and in there under details..there i see type= CanOnlyApplyOnceException. here is my code:
protected void AddNewApplication()
{
try
{
using (var proxy = new ServiceReference1.ServiceClient())
{
proxy.AddApplication(new Application
{
Credentials = 2,
Comments = txtComments.Text,
});
}
}
catch (CanOnlyApplyOnceException c)
{
ErrorSummary.AddError(c.Message, this);
return;
}
catch (Exception)
{
lblStatus.Text = "There has been an error. Please try again";
}
}
© Stack Overflow or respective owner