title: When is it better to use exit() vs exceptions in c++?
body: <p>I am writing a program where depending on input values, the code will terminate. That led me to think of the best way to implement this generally. I can easily come up with two examples:</p>
  
  <pre class="lang-cpp prettyprint-override"><code>if (bad_value) {
      clean_up();
      exit(1);
  }
  </code></pre>
  
  <p>and something like this</p>
  
  <pre class="lang-cpp prettyprint-override"><code>try
      myFunc();
  catch myException {
      clean_up();
      exit(1);
  }
  
  int myFunc() {
      if (badValue) throw myException;
      ...
  }
  </code></pre>
  
  <p>The first code block seems much cleaner so I wonder why you would want to ever use exceptions? I guess this is really a battle of <code>c</code> vs <code>c++</code>.</p>