I have a web service that’s pretty simple; something like this:
public class LeadService : System.Web.Services.WebService {
[WebMethod(EnableSession = true)]
public string MyService(string TheIncomingData)
{
string ReturnData = "";
MyClass TheClass = new MyClass();
ReturnData = TheClass.MyMethod(TheIncomingData);
return ReturnData;
}
}
You might have guessed it, the MyMethod is a pretty long-running method with some room for errors (for now). If I add a try/catch statement around the method call like this:
try { ReturnData = TheClass.MyMethod(TheIncomingData); }
catch { ReturnData = ""; }
Is this going to make the service and the app exception-proof? And, is using a try statement like this going to have any performance impact even if no error occurs?
Thanks for your advice.
Is using a
trystatement like this going to have any performance impact even if no error occurs?No.
Is the application exception-proof?
Yes. However if you have
onApplicationErrorevent in theGlobal.asaxyou won’t be able to see the error since you are not throwing a new one.But the way I see it for now, your code is safe from exceptions.