title: When is a function try block useful?
body: <p>I'm wondering when programmers use function try blocks. When is it useful?</p>
  
  <pre><code>void f(int i)
  try
  {
     if ( i  &lt; 0 ) 
        throw "less than zero";
     std::cout &lt;&lt; "greater than zero" &lt;&lt; std::endl;
  }
  catch(const char* e)
  {
      std::cout &lt;&lt; e &lt;&lt; std::endl;
  }
  
  int main() {
          f(1);
          f(-1);
          return 0;
  }
  </code></pre>
  
  <p>Output: (at <a href="http://ideone.com/BcBo9" rel="noreferrer">ideone</a>)</p>
  
  <pre><code>greater than zero
  less than zero
  </code></pre>
  
  <p>EDIT: As some people might think that the syntax of function defintion is incorrect (because the syntax doesn't look familiar), I've to say that no its not incorrect. Its called function-try-block. See §8.4/1 [dcl.fct.def] in the C++  Standard.</p>