title: How to pass a raised error on a singular matrix of np.linalg.inv function?
body: <p>I created a singular matrix. </p>
  
  <pre class="lang-py prettyprint-override"><code>mat = np.array([[   1,    8,   50],
   [   8,   64,  400],
   [  50,  400, 2500]])
  </code></pre>
  
  <p>Knowing already that creation of the inverse of <code>mat</code> will raise a LinAlgError, my aim of this is to pass the exception by the <code>try</code> and <code>exception</code> process.</p>
  
  <p>So I tried, this :</p>
  
  <pre><code>try:
      np.linalg.inv(mat)
  except LinAlgError:
      print('yes')
  </code></pre>
  
  <p>and this :</p>
  
  <pre><code>try:
      np.linalg.inv(mat)
  except LinAlgError("Singular matrix"):
      print('yes')
  </code></pre>
  
  <p>and this:</p>
  
  <pre><code>try:
      np.linalg.inv(mat)
  except numpy.linalg.LinAlgError:
      print('yes')
  </code></pre>
  
  <p>I always get the same stackoverflow for the several tries saying that i created a exception by trying to handle the first exception </p>
  
  <pre><code>Traceback (most recent call last):
    File "&lt;ipython-input-18-de9bc8aa3ed1&gt;", line 2, in &lt;module&gt;
      np.linalg.inv(mat)
    File "C:\Users\Azerty\PycharmProjects\OptionsHedgeFund\venv37\lib\site-packages\numpy\linalg\linalg.py", line 551, in inv
      ainv = _umath_linalg.inv(a, signature=signature, extobj=extobj)
    File "C:\Users\Azerty\PycharmProjects\OptionsHedgeFund\venv37\lib\site-packages\numpy\linalg\linalg.py", line 97, in _raise_linalgerror_singular
      raise LinAlgError("Singular matrix")
  numpy.linalg.LinAlgError: Singular matrix
  During handling of the above exception, another exception occurred:
  Traceback (most recent call last):
    File "C:\Users\Azerty\PycharmProjects\OptionsHedgeFund\venv37\lib\site-packages\IPython\core\interactiveshell.py", line 3326, in run_code
      exec(code_obj, self.user_global_ns, self.user_ns)
    File "&lt;ipython-input-18-de9bc8aa3ed1&gt;", line 3, in &lt;module&gt;
      except numpy.linalg.LinAlgError:
  NameError: name 'numpy' is not defined
  </code></pre>
  
  <p>Do you know how to define the <code>LinAlgError</code> in <code>exception ... :</code> ?</p>