title: Report MemoryError and OverflowError arbitrarily
body: <p>I employed the "Sieve of Eratosthenes" to produce primes.</p>
  
  <pre><code>def primes(n):
      if n &lt; 2:
          return None
      primes_sieve = [True] * (n + 1) 
      primes_sieve[1] = False
      primes_sieve[0] = False
  
      # sieve
      for i in range(2, int(n ** 0.5) + 1):  
          if primes_sieve[i]:
              for j in range(i * i, n + 1, i):  
                  primes_sieve[j] = False
  
      return [i for i, p in enumerate(primes_sieve) if p]
  </code></pre>
  
  <p>It works well for small numbers.</p>
  
  <pre><code>In [28]: primes(2**10)[:10]              
  Out[28]: [2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
  In [29]: primes(2**10)[-10:]             
  Out[29]: [967, 971, 977, 983, 991, 997, 1009, 1013, 1019, 1021]
  In [30]: primes(2**15)[-10:]             
  Out[30]: [32633, 32647, 32653, 32687, 32693, 32707, 32713, 32717, 32719, 32749]
  </code></pre>
  
  <p>For some big numbers, it report errors arbitrarily.</p>
  
  <p>Memory Error</p>
  
  <pre><code>In [32]: primes(2**30)[-10:]             
  ---------------------------------------------------------------------------
  MemoryError                               Traceback (most recent call last)
  &lt;ipython-input-32-3e546166a3d9&gt; in &lt;module&gt;
  ----&gt; 1 primes(2**30)[-10:]
  
  &lt;ipython-input-26-5f07bf9cb49e&gt; in primes(n)
        2     if n &lt; 2:
        3         return None
  ----&gt; 4     primes_sieve = [True] * (n + 1)
        5     primes_sieve[1] = False
        6     primes_sieve[0] = False
  
  MemoryError: 
  </code></pre>
  
  <p>and  OverflowError:</p>
  
  <pre><code>In [35]: primes(2**100)[-10:]            
  ---------------------------------------------------------------------------
  OverflowError                             Traceback (most recent call last)
  &lt;ipython-input-35-3bb8857d5f28&gt; in &lt;module&gt;
  ----&gt; 1 primes(2**100)[-10:]
  
  &lt;ipython-input-26-5f07bf9cb49e&gt; in primes(n)
        2     if n &lt; 2:
        3         return None
  ----&gt; 4     primes_sieve = [True] * (n + 1)
        5     primes_sieve[1] = False
        6     primes_sieve[0] = False
  
  OverflowError: cannot fit 'int' into an index-sized integer
  </code></pre>
  
  <p>What's the problem? I am delighted and curious to find that python has OverflowError as well.</p>