I have a requirement to throw an exception if I encounter a specific error and return an object in that case.
So I want to do something like this:
if(error)
return obj;
throw new FaultException(string.Format("Error found with ID={0}", ID))
This will not work obviously, as return will prevent the exception from being thrown.
Can anyone suggest whats the best way to achive this. Can I pass the object in the exception somehow?
Thanks
Normally you would create your own exception class which would contain all your data. But I see
FaultExceptionwhich implies WCF, and for that there’s alreadyFaultException<T>.