exceptions

Larry Bates lbates at swamisoft.com
Tue Jun 1 12:13:12 EDT 2004


I'm going to jump in here and make an observation.
It sounds like you have too much code in a single
try/except block.  If you have independent calls
to instrument interface put each of them that might
fail in a separate try/except block.  I've needed
to do this in an earlier project and I log errors
in a log file for review.

Something like:

try: data=getsomedatafrominstrumentfunc1()
except:
    logf.writelines("W","Unable to communicate with func1")

try: data=getsomedatafrominstrumentfunc2()
except:
    logf.writelines("W","Unable to communicate with func2")

My understanding is that try/except overhead is very low
(especially if there is not an exception).

HTH,
Larry Bates
Syscon, Inc.

"Zunbeltz Izaola" <zunbeltz at wm.lc.ehu.es.XXX> wrote in message
news:cthvfiblpo4.fsf at lcpxdf.wm.lc.ehu.es...
> Peter Hansen <peter at engcorp.com> writes:
>
>
> > Pardon: I don't know why I thought this was related to testing
> > code.
>
> No problem :-)
>
> >
> > > My program is controling and instrument (an x-ray powder
> > > diffractometer) and some parts of the instrument are not working for
> > > the moment, so i want to disable all error i get from this instrument
> > > (are coded like exceptions)
> >
> > What is the interface to the instrument?  Is there some sort of
> > driver/wrapper layer that handles the communication with the
> > device?  Your only hope, I think, is to intercept things at
> > that level and avoid/trap the exceptions before they get up
> > to the higher level.  In effect, stubs as Irmen suggested...
> >
>
> Finally I do something similar to Irmen's suggestion.
>
> > It sounds like you are quite capable of figuring it out at
> > this point, though, since all you wanted to know was whether
> > you could continue after an exception and now you know you
> > cannot. :-)
> >
>
> Yes, I only wanted to know if there was an easy way to continue after
> an exception; and I can't (nobody can :-)
>
> Thanks to all for your answers (and sorry for re-starting and annual
> thread)
>
> Zunbeltz
>
> > -Peter
>
> -- 
> Zunbeltz Izaola Azkona                    |  wmbizazz at lg dot ehu
> dotes
> Materia Kondentsatuaren Fisika Saila      |
> Zientzia eta Teknologia Fakultatea        |  Phone: 34946015326
> Euskal Herriko Unibertsitatea             |
> PK 644                                    |  Fax:   34 944648500
> 48080 Bilbo (SPAIN)                       |





More information about the Python-list mailing list