[Numpy-discussion] how can one catch a multiarray.error

Robert Kern robert.kern at gmail.com
Mon Jun 1 22:43:59 EDT 2009


On Mon, Jun 1, 2009 at 21:37,  <josef.pktd at gmail.com> wrote:
> how do we catch a multiarray.error in a try except clause?
>
> e.g.
>>>> np.argmin([])
> Traceback (most recent call last):
>  File "<pyshell#147>", line 1, in <module>
>    np.argmin([])
>  File "C:\Programs\Python25\Lib\site-packages\numpy\core\fromnumeric.py",
> line 631, in argmin
>    return _wrapit(a, 'argmin', axis)
>  File "C:\Programs\Python25\Lib\site-packages\numpy\core\fromnumeric.py",
> line 37, in _wrapit
>    result = getattr(asarray(obj),method)(*args, **kwds)
> multiarray.error: attempt to get argmax/argmin of an empty sequence

try:
   ...
except numpy.core.multiarray.error:
   ...

Unfortunately, that is still a string exception. We should change that.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco



More information about the NumPy-Discussion mailing list