Im using python and writing to a tag, if the tag fails to write, i get a red error box on the screen. I want to catch the error but the generic catch wont stop the error. Does anyone know the error type i need to catch?
Here is the error:
ERROR [ClientTagUtilities-AWT-EventQueue-2] Error writing to tag RFID/string_input_ignition_uid_get
Bad Quality
The system.tag.write function has a third optional parameter called “suppressErrors”. Try setting that to True. For example: system.tag.write(tagPath, value, True)
If you actually want to catch an exception when writing to a tag then you could try using system.tag.writeSynchronous.
The reason you can’t catch an exception when using system.tag.write is because it is executed in a separate thread than your script that calls system.tag.write. Because of this system.tag.write is considered an asynchronous function.
The function system.tag.writeSynchronous is not asynchronous. It is executed in the same thread that it is called in and it is executed directly after it is called.
You could use the following function to still achieve asynchronous tag writes but be able to catch exceptions when writing to a tag fails:
def tagWrite(tagPath,value):
import sys,system
def func():
try:
system.tag.writeSynchronous(tagPath, value)
except:
#get and print out information about the exception that was raised
print sys.exc_info()
system.util.invokeAsynchronous(func)