title: Using Try/catch with Do/While
body: <p>this is more of a conceptual question.</p>
  
  <p>Is it aceptable/good programming mixing do/while loops with try/catch?</p>
  
  <p>ex:</p>
  
  <pre><code>&lt;?php
  function main() {
  
      $failure = 0;
      do {
         $failure += foo();
         $failure += bar();
         ...
         if ($failure) { return $failure; }
      } 
      while ($failure == 0);
  }
  
  function foo() {
      try {
          echo 'DO FOO STUFF&lt;br /&gt;';
          return 0;
      } 
      catch (Exception $e) {
          return 1;
      }
  }
  
  function bar() {
      try {
          echo 'DO BAR STUFF&lt;br /&gt;';
          return 0;
      } 
      catch (Exception $e) {
          return 1;
      }
  }
  ?&gt;
  </code></pre>
  
  <p>The reason I'm asking is that I read somewhere that mixing both is bad practice. You should create your own exceptions and "throw" them instead. But isn't that a bit of an overkill?</p>
  
  <p>EDIT:
  To explain the scenario where this question emerged, imagine a robot that has to follow a line. The robot calculates its position (X position, Y poistion, Z position and "postural" position) everytime he takes a step and sends the information to a server. Server doublechecks this information. If any anomaly is found, servers sends a "stop" signal to the robot. The robot stops, recalculates its position, resends information and waits for a "go" signal.</p>
  
  <p>This loop example was based on the data feed received from the robot. If something went wrong, (like a broken wireless link, or an obstacle, or a misstep) the robot must stop to prevent going astray, or falling, or anything. We aren't interested in knowing what went wrong, or why it went wrong, just that it went wrong (or not). (that is actually taken care in another part of the code, not PHP based, the Debug Module).</p>
  
  <p>EDIT 2:
  Like everyone pointed out, seems the right approach is to properly raise/handle the exceptions.
  Since everyone seems to agree in this, I don't know who to award the "right answer" tick.
  I will wait a few days and give it to the one with more votes if that's ok!</p>