> So I have a function that ries to add a record:
>
> def EntryAdd(self, dataDict):
> try:
> self._DBConn.MoveFirst()
> self._DBConn.AddNew()
> for key, value in dataDict.items():
> self._DBConn.Fields.Item(key).Value = value
> self._DBConn.Update()
> except pywintypes.com_error, e:
> print e
> print 'error text here'
> return True
>
> So if the error already exists I get an exception, no
> problem, I handle and
> log it.
In general, you should try and be specific about handling exceptions.
Assuming you want to only handle "record exists" type exceptions, you should
probably write something closer to:
def EntryAdd(self, dataDict):
self._DBConn.MoveFirst()
self._DBConn.AddNew()
for key, value in dataDict.items():
self._DBConn.Fields.Item(key).Value = value
try:
self._DBConn.Update()
except pywintypes.com_error, e:
hr, msg, exc = e
if hr != SOME_CONSTANT_MEANING_RECORD_EXISTS:
raise
print e
print 'record exists'
return True
I'm not sure what SOME_CONSTANT_MEANING_RECORD_EXISTS is, and it may even be
necessary to unpacl 'exc' to get a reliable error code. All other errors
will still result in an uncaught exception - so any other errors you have
are not silently handled as if they were the common "record exists". You
probably still want an outer exception handler that handles all errors in a
sane way
Mark
_______________________________________________
Python-win32 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-win32