<p>Here's a question to expose my lack of experience: I have a method <strong>DoSomething()</strong> which throws an exception if it doesn't manage to do it cleanly. If it fails, I try the less accurate method <strong>DoSomethingApproximately()</strong> several times in the hope that it will find a sufficiently good solution; if this also fails I finally call <strong>DoSomethingInaccurateButGuaranteedToWork()</strong>. All three are methods belonging to this object.</p>

<p>Two questions: first, is this (admittedly ugly) pattern acceptable, or is there a more elegant way?</p>

<p>Second, what is the best way to keep track of how many times I have called <strong>DoSomethingApproximately()</strong>, given that it is likely to throw an exception? I am currently keeping a variable iNoOfAttempts in the object, and nesting try blocks... this is horrible and I am ashamed. </p>

Return an error code instead of throwing an exception.
If the ways those methods fail do throw exceptions, catch them all in the same method and take appropriate action, like increasing a counter and returning an error code.
```
```
bool result = DoSomething();
   while (!result && tries < MAX_TRIES) {
       result = DoSomethingApproximately(); //This will increment tries
       if (tries > THRESHOLD) {
           result = DoSomethingThatAlwaysWorks();
       }
   }
```
```