Return error and throw exception

Viewed 2728

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

5 Answers
Related