Position of the try catch statement
c#
Solution
Typically you want to allow your exceptions propagate up to your application boundaries. You're only going to want to do one of a few things with your exception:
- Wrap it
- Replace it
- Let it propagate
Update
From your question it seems that you are looking for a fault tolerant solution for your web service calls. This is a more complex problem than simply "where do I put my try-catch?" You would still place your exception handling at the application boundary, but there you would implement your fault tolerance strategy. This would need to have many considerations, including asynchronously calling your web service, number of retry attempts, etc. I would suggest doing a search for web service fault tolerance.
Problem
I have some code that currently looks somewhat like this: ``` public void MainFunction() { try { SomeProblemFunction(); } catch { AllFineFunction(); } } private void SomeProblemFunction() { ... } private void AllFineFunction() { ... } ``` As you can see, I'm currently wrapping the call to `SomeProblemFunction` around a `try` statement because that function could fail (it relies on an outside web service call). My question is this: should the `try` statement be a) outside the problem function (like I have it now) or b) inside the problem function?