
Originally Posted by
pedja089
Not necessarlly, Lot of hi level programing language have this already implemented. eg in .net: On Error GoTo, Try, catch, etc...
hmm, in python at least a sub with a "try" still returns , even if the processing aborts and executes an "try" error routine.
i see no goto or stack popping going on.
a couple of python subs with try
Code:
def process_d(tname,q): while exitflg==0:
dx=ser.readline()
try :
rt='s'
ff= string.rstrip(dx)
int(ff,16) ##non hex chr will cause ValueError
if dx[0]=='A':
rt='w'
#print dx
ts=str(datetime.datetime.now())[:19]
r_x=[ts,dx,rt]
queueLock.acquire()
q.put(r_x)
queueLock.release()
except ValueError:
#print dx
dx=[]
def bag_reading ():
global readings
bag_data_time =datetime.datetime.now()
if len(readings)>0:
try:
conn=sqlite3.connect('/media/CORSAIR/wh2.db')
curs=conn.cursor()
curs.executemany("INSERT INTO log values((?),(?),(?),(?))", (readings))
# commit the changes
conn.commit()
conn.close()
print 'write ',len(readings),' ',readings[-1][0]
readings=[]
bag_data_time += datetime.timedelta(minutes=5)
except sqlite3.OperationalError as err :
print 'db busy',err
bag_data_time += datetime.timedelta(minutes=1)
return bag_data_time
Bookmarks