title: The proper Python exception to break out of an infinite loop (that shouldnt be infinite)
body: <p>Here's my simplified code:</p>
  
  <pre><code>x = 0
  while True:
      x += 1
      if not do_stuff(x)
          break
      if x &gt; 1000000:
          raise Exception("Too many iterations")
  </code></pre>
  
  <p>1000000 is a value for <code>x</code> that should never be reached. If it is, something has gone wrong and an exception is raised. What would be the proper subclass of <code>Exception</code> for such a use case, if any exists at all?</p>