I’m working on a project that relies extensively on Exchange Web Services. As of now I’m wrapping all of my service calls on try/catch. While this isn’t a problem per say it does clutter code quite a bit by having one line turn into 10~.
Here are the options I see:
- Create a function such as
bool TryExecute(Action action, Action failCallback) - Interface all of my service calls and use an interceptor to wrap my calls
Are these any alternatives that I’m missing?
that depends on your implementation. I would place the try/catch as near to the point where failure is expected (and can be gracefully handeled) as possible.
For example wrapping those calls into a interface (for testing) and using only a common exception-type otherwise (for example handle EndpointNotFound and wrap any unexpected failure into a ExchangeCommunication-Exception you created yourself).
Both of your options seems to handle every kind of error, and I would not advise this but aside from that it’s surely better than going against DRY