title: How to avoid using exceptions, as a form of control flow, to jump through through deeply nested function calls?
body: <p>I've currently been using custom exceptions to achieve the goal of jumping through deeply nested function calls, to get to a specific function in the call chain. For example, consider the following code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  struct label {};
  
  void B();
  void C();
  void D();
  
  void A() {
      return B();
  }
  
  void B() { // I want to jump to the level of the B function in the call-chain.
      try {
          return C();
      }
      catch(const label&amp; e) {
          std::cout &lt;&lt; "jumped to b function" &lt;&lt; std::endl;
      }
  }
  
  void C() {
      return D();
  }
  
  void D() {
      throw label();
  }
  
  int main() {
      A();
      return 0;
  }
  </code></pre>
  
  <p>Note however that the above example is extremely contrived, and is simply for illustration purposes. In my actual code, I'm using this technique in a recursive-decent parser to recover from syntactical errors. Also note that I'm not using exceptions to jump around to different functions, like a glorified <code>goto</code>. <em>I'm using the custom exception to <strong>always jump to one</strong> specific function near the top of the call chain</em>.</p>
  
  <p>The above code does work fine, but reading some of the top posts on the question <a href="https://softwareengineering.stackexchange.com/questions/189222/are-exceptions-as-control-flow-considered-a-serious-antipattern-if-so-why"><em>Are exceptions as control flow considered a serious antipattern? If so, Why?</em> (on the Software Engineering site)</a>, suggested that using exceptions in such a manner as the above scenario does, is consider an anti-pattern, and there are usually better was to accomplish one's goal.</p>
  
  <p>Is my usage of a custom exception above appropriate? If not, what is a more reasonable way to accomplish my goal while avoiding using exactions as a form control flow? (Also, although I tagged this question as <a href="/questions/tagged/c%2b%2b" class="post-tag" title="show questions tagged &#39;c++&#39;" rel="tag">c++</a> since that's what I'm writing my parser in, I suppose this is a more language-agnostic question.)</p>