[Numpy-discussion] Question about improving genfromtxt errors

Ralf Gommers ralf.gommers@googlemail....
Fri Sep 25 14:28:19 CDT 2009


On Fri, Sep 25, 2009 at 3:08 PM, Christopher Barker
<Chris.Barker@noaa.gov>wrote:

> Ralf Gommers wrote:
> > Probably the easiest for your purpose is this:
> >
> > def divbyzero():
> >     return 1/0
> >
> > try:
> >     a = divbyzero()
> > except ZeroDivisionError as err:
> >     print 'problem occurred at line X'
> >     raise err
>
> I get an error with this syntax -- is thin 2.6 only?
>
> Yes sorry, that's the 2.6/3.0 syntax. It should be
except ZeroDivisionError, err:
Anyway, the instance is not needed in my example because it can't be
usefully modified and can be re-raised with a bare "raise".


> >
> > Maybe better to use a logger instead of print, but you get the idea.
>
> definitely don't print! a lib function should never print (unless maybe
> with a debug flag or something set). I don't know if there is a standard
> logging approach you could use.
>
> I'd rather see info added to the Exception, or a new Exception raised
> with info.
>

The former is not possible, which motivated my example. The latter loses the
original traceback. Logging seems to be the way to go if you want all the
info.

Cheers,
Ralf
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20090925/7ca95325/attachment-0001.html 


More information about the NumPy-Discussion mailing list