On Fri, Sep 25, 2009 at 3:08 PM, Christopher Barker <[email protected]>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
_______________________________________________ NumPy-Discussion mailing list [email protected] http://mail.scipy.org/mailman/listinfo/numpy-discussion
