title: Should break/continue/return be interrupted by an exception?
body: <p>I came upon an interesting scenario with flow control while working on my language. What happens if an exception is thrown while processing a <code>break</code> statement. GCC seems to believe the break flow is lost, but the standard seems somewhat silent on what should happen.</p>
  
  <p>For example, what should the following program actually do?</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  struct maybe_fail {
      bool fail;
      ~maybe_fail() {
          if( fail )
              throw 1;
      }
  };
  
  int main() {
      for( int i=0; i &lt; 6; ++i ) {
          cout &lt;&lt; "Loop: " &lt;&lt; i &lt;&lt; endl;
  
          try {
              maybe_fail mf;
              mf.fail = i % 2;
              if( i == 3 )
                  break;
  
          } catch( int ) {
              cout &lt;&lt; "Caught" &lt;&lt; endl;
          }
      }
      return 0;
  }
  </code></pre>
  
  <p>Note that a <code>return</code> will also be blocked, as will a <code>continue</code> (add output after the catch to see that). Attempt to <code>goto</code> outside of the block will also be caught.</p>
  
  <p>What is the correct flow? The standard doesn't seem to address this: section 6.6 on jump statements makes no mention, neither does section 15 on exception handling. I do understand that exceptions in destructors is in terribly bad form, but if you are using something like BOOST_SCOPE_EXIT for defer statements this behaviour might become quite important.</p>
  
  <p><em>Perhaps of interest, the same flow happens in Java and Python, so at least there seems to be some consistency in the imperative languages.</em></p>