# system.tag.writeBlocking() not handled by try/except block

**URL:** <https://forum.inductiveautomation.com/t/system-tag-writeblocking-not-handled-by-try-except-block/102850>\
**Category:** Ignition\
**Tags:** scripting, ignition81\
**Created:** [February 25, 2025, 4:17pm UTC](https://forum.inductiveautomation.com/t/system-tag-writeblocking-not-handled-by-try-except-block/102850 "2025-02-25T16:17:28Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jules\_Lalu](https://avatars.discourse-cdn.com/v4/letter/j/47e85d/32.png) [@Jules\_Lalu](https://forum.inductiveautomation.com/u/Jules_Lalu)\
**Post date:** [February 25, 2025, 4:17pm UTC](https://forum.inductiveautomation.com/t/system-tag-writeblocking-not-handled-by-try-except-block/102850/1 "2025-02-25T16:17:28Z")

</div>

Hi,

I am trying to catch timeouts of system.tag.writeBlocking() function (Ignition version 8.1.32).  
For testing purposes, I have configured a tag change script on a tag that switches to 0 every 4 seconds.

```python
def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
	if currentValue.value == 0: 
		logger = system.util.getLogger("handling_timeout_test")
		logger.warn("writing on opc tag")
		values = [system.date.getSecond(system.date.now())]
		try:
			system.tag.writeBlocking(["[default]TAG_WITH_LATENCY"], values, 300)
		except:
			logger.error("failed writing on opc tag")

```

The tag TAG\_WITH\_LATENCY points to an OPC server that has a 1 second latency for every write.

However, the timeout error is not catched properly, and I get "Error during blocking write of tags through scripting." in the gateway logs :

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/a/4a2bc29a5b95bb90afb3e5fc44e1409bbb71e2df.png)  
I don't get the error log that I put in the except clause either.

If I try to execute this same script from the script console on my designer though, the timeout is caught properly.

Would anyone have any idea about the root cause of such behavior ? Thanks in advance for your help !

---

<div class="post-metadata">

**Author:** ![flexware](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/flexware/32/66243_2.png) [@flexware](https://forum.inductiveautomation.com/u/flexware)\
**Post date:** [February 25, 2025, 4:30pm UTC](https://forum.inductiveautomation.com/t/system-tag-writeblocking-not-handled-by-try-except-block/102850/2 "2025-02-25T16:30:56Z")

</div>

The 300 you specify there seems to be 300ms, so if your write doesn't happen within that time, you'll get a timeout error. I'm not sure that this is the issue, but that's what I wanted to bring up after a quick glance at the docs.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/b/a/ba4fce25a27a34583e7b7e9253820a386130390f.png)

---

<div class="post-metadata">

**Author:** ![Jules\_Lalu](https://avatars.discourse-cdn.com/v4/letter/j/47e85d/32.png) [@Jules\_Lalu](https://forum.inductiveautomation.com/u/Jules_Lalu)\
**Post date:** [February 25, 2025, 4:34pm UTC](https://forum.inductiveautomation.com/t/system-tag-writeblocking-not-handled-by-try-except-block/102850/3 "2025-02-25T16:34:03Z")

</div>

Yes, you are right. However, when the function times out, I would expect the error to be caught by my try/except block. Turns out it's not the case..

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [February 25, 2025, 4:35pm UTC](https://forum.inductiveautomation.com/t/system-tag-writeblocking-not-handled-by-try-except-block/102850/4 "2025-02-25T16:35:28Z")

</div>

For complicated reasons, _Jython_ exceptions are distinct from _Java_ exceptions, and so you need to catch _both_, separately:

> [@Catch IOException?](https://forum.inductiveautomation.com/t/catch-ioexception/18612/3):
>
> Consider using two except blocks, as jython’s standard Exception won’t catch pure java exceptions. Like so: import java.lang.Exception try: # something something something except Exception, e: # jython exception except java.lang.Exception, e: # java exception

---

<div class="post-metadata">

**Author:** ![Leor\_Fishman](https://avatars.discourse-cdn.com/v4/letter/l/e19adc/32.png) [@Leor\_Fishman](https://forum.inductiveautomation.com/u/Leor_Fishman)\
**Post date:** [February 25, 2025, 4:38pm UTC](https://forum.inductiveautomation.com/t/system-tag-writeblocking-not-handled-by-try-except-block/102850/5 "2025-02-25T16:38:39Z")

</div>

That's interesting --  
this is still the case even with a bare except?  
I would expect that to grab anything, not type specific

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 25, 2025, 4:38pm UTC](https://forum.inductiveautomation.com/t/system-tag-writeblocking-not-handled-by-try-except-block/102850/6 "2025-02-25T16:38:52Z")

</div>

Now-a-days, I recommend using `java.lang.Throwable` instead of `java.lang.Exception`, so that you don't have any name collision with python's `Exception` class, and to also catch Java `Error` instances.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [February 25, 2025, 4:39pm UTC](https://forum.inductiveautomation.com/t/system-tag-writeblocking-not-handled-by-try-except-block/102850/7 "2025-02-25T16:39:35Z")

</div>

Yes, it's still the case.

---

<div class="post-metadata">

**Author:** ![Jules\_Lalu](https://avatars.discourse-cdn.com/v4/letter/j/47e85d/32.png) [@Jules\_Lalu](https://forum.inductiveautomation.com/u/Jules_Lalu)\
**Post date:** [February 25, 2025, 4:50pm UTC](https://forum.inductiveautomation.com/t/system-tag-writeblocking-not-handled-by-try-except-block/102850/8 "2025-02-25T16:50:50Z")

</div>

Thank you for all your answers and for the insights, I did not know that except: clause alone did not catch Java errors.  
Nevertheless, I have modified my script to use java.lang.Throwable and it still has not solved the issue...  
Below is the updated script :

```python
def valueChanged(tag, tagPath, previousValue, currentValue, initialChange, missedEvents):
    import java.lang.Throwable
	if currentValue.value == 0: 
		logger = system.util.getLogger("handling_timeout_test")
		logger.warn("writing on opc tag")
		values = [system.date.getSecond(system.date.now())]
		try:
			system.tag.writeBlocking(["[default]TAG_WITH_LATENCY"], values, 300)
		except java.lang.Throwable, e:
			logger.error("java Exception : failed writing on opc tag")
		except:
			logger.error("failed writing on opc tag")

```

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [February 25, 2025, 4:53pm UTC](https://forum.inductiveautomation.com/t/system-tag-writeblocking-not-handled-by-try-except-block/102850/9 "2025-02-25T16:53:33Z")

</div>

The Exception is being caught and logged, it's not re-thrown. There will be a QualityCode.Error\_Exception at the corresponding index for the results of the call.

edit: actually all of the results will be Error\_Exception in this case.

It seems the implementation is inconsistent between Client and Gateway scopes. Client scope wraps and re-throws via `Py.JavaError(e)`.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [February 25, 2025, 5:00pm UTC](https://forum.inductiveautomation.com/t/system-tag-writeblocking-not-handled-by-try-except-block/102850/10 "2025-02-25T17:00:05Z")

</div>

Why are you not collecting and examining the quality codes returned from `writeBlocking()` ? That's how most problems are reported.

---

<div class="post-metadata">

**Author:** ![Jules\_Lalu](https://avatars.discourse-cdn.com/v4/letter/j/47e85d/32.png) [@Jules\_Lalu](https://forum.inductiveautomation.com/u/Jules_Lalu)\
**Post date:** [February 25, 2025, 5:09pm UTC](https://forum.inductiveautomation.com/t/system-tag-writeblocking-not-handled-by-try-except-block/102850/11 "2025-02-25T17:09:54Z")

</div>

Ok thank you very much for this explanation ! If I understood well, the code does not go into the except clause at all so I am not seeing those logs.  
Is there a way I can remove this timeout log that appears on the gateway still ? I find it hard to troubleshoot, I prefer to implement custom logs describing which tags timed out following the method @pturmel mentioned.

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [February 25, 2025, 5:10pm UTC](https://forum.inductiveautomation.com/t/system-tag-writeblocking-not-handled-by-try-except-block/102850/12 "2025-02-25T17:10:52Z")

</div>

Unfortunately the only thing you could do is turn that logger (`Scripting[system_util_tag]`) off entirely, which means you wouldn't see any log messages from it at all, perhaps hiding other issues.

---

<div class="post-metadata">

**Author:** ![Jules\_Lalu](https://avatars.discourse-cdn.com/v4/letter/j/47e85d/32.png) [@Jules\_Lalu](https://forum.inductiveautomation.com/u/Jules_Lalu)\
**Post date:** [February 25, 2025, 5:52pm UTC](https://forum.inductiveautomation.com/t/system-tag-writeblocking-not-handled-by-try-except-block/102850/13 "2025-02-25T17:52:29Z")

</div>

Sorry one last question because I read too fast earlier on:

> edit: actually all of the results will be Error\_Exception in this case.

This means that even if the write to a single tag times out and the other writes are successful, QualityCode of Error\_Expression will be returned for every write ?  
Is there a way to know which write has timed out precisely ?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [February 25, 2025, 5:54pm UTC](https://forum.inductiveautomation.com/t/system-tag-writeblocking-not-handled-by-try-except-block/102850/14 "2025-02-25T17:54:17Z")

</div>

No, because the timeout isn't per tag, it's for the whole call. If it times out, the entire batch that was submitted got no results. We have no idea what writes were successful at that point.

---

<div class="post-metadata">

**Author:** ![Jules\_Lalu](https://avatars.discourse-cdn.com/v4/letter/j/47e85d/32.png) [@Jules\_Lalu](https://forum.inductiveautomation.com/u/Jules_Lalu)\
**Post date:** [February 25, 2025, 5:55pm UTC](https://forum.inductiveautomation.com/t/system-tag-writeblocking-not-handled-by-try-except-block/102850/15 "2025-02-25T17:55:39Z")

</div>

Ah, that's an issue... would you advise another way of writing to a batch of tags that would handle this kind of problem ?

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [February 25, 2025, 5:57pm UTC](https://forum.inductiveautomation.com/t/system-tag-writeblocking-not-handled-by-try-except-block/102850/16 "2025-02-25T17:57:24Z")

</div>

There isn't one, you can't have both batch performance _and_ individual tag timeout/result.

You can loop and write one tag at a time and pay the performance penalty if you absolutely need per tag timeout/result.
