# Try catch on system.tag.write

**URL:** <https://forum.inductiveautomation.com/t/try-catch-on-system-tag-write/8566>\
**Category:** Ignition\
**Created:** [June 13, 2014, 2:43pm UTC](https://forum.inductiveautomation.com/t/try-catch-on-system-tag-write/8566 "2014-06-13T14:43:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![drewdin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drewdin/32/3363_2.png) [@drewdin](https://forum.inductiveautomation.com/u/drewdin)\
**Post date:** [June 13, 2014, 2:43pm UTC](https://forum.inductiveautomation.com/t/try-catch-on-system-tag-write/8566/1 "2014-06-13T14:43:49Z")

</div>

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`

Thanks

---

<div class="post-metadata">

**Author:** ![adamaustin](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@adamaustin](https://forum.inductiveautomation.com/u/adamaustin)\
**Post date:** [June 16, 2014, 9:03pm UTC](https://forum.inductiveautomation.com/t/try-catch-on-system-tag-write/8566/2 "2014-06-16T21:03:32Z")

</div>

You could try instead to follow the write with a read and then look at the intValue of the [Quality Overlay](http://inductiveautomation.com/support/usermanuals/ignition/quality_overlays.htm):

```auto
system.tag.write("MyTag", value)
qv = system.tag.read("MyTag")
print qv.quality.intValue
```

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [June 22, 2014, 3:01am UTC](https://forum.inductiveautomation.com/t/try-catch-on-system-tag-write/8566/3 "2014-06-22T03:01:43Z")

</div>

Here are a couple ideas:

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)`

---

<div class="post-metadata">

**Author:** ![drewdin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drewdin/32/3363_2.png) [@drewdin](https://forum.inductiveautomation.com/u/drewdin)\
**Post date:** [June 24, 2014, 11:50am UTC](https://forum.inductiveautomation.com/t/try-catch-on-system-tag-write/8566/4 "2014-06-24T11:50:12Z")

</div>

Thanks, I ended up using the system.opc.write and used the isGood() to let me know if the write failed or not.

I appreciate the background on how the tags work!
