title: Is it possible to define an exception inside a function
body: <p>One way to implement "early returns" in OCaml is via exceptions:</p>
  
  <pre><code>exception Exit
  
  let myfunc () = 
      try
        for i = 0 to .... do
          if .. then raise Exit
        done; false
      with Exit -&gt; true
  </code></pre>
  
  <p>However, is there a way to declare this <code>Exit</code> exception in the body of the function, so its name is not visible to other functions in the module?</p>
  
  <pre><code>(* I would like to do this, but it gives a syntax error *)
  let myfunc () = 
      exception Exit
      try
        for i = 0 to .... do
          if .. then raise Exit
        done; false
      with Exit -&gt; true
  </code></pre>