Reputation: 540
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:
bool TryExecute(Action action, Action failCallback)
Are these any alternatives that I'm missing?
Upvotes: 1
Views: 83
Reputation: 52290
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
Upvotes: 2