# Try Except when reading tags

**URL:** <https://forum.inductiveautomation.com/t/try-except-when-reading-tags/16179>\
**Category:** Ignition\
**Created:** [November 30, 2017, 4:10pm UTC](https://forum.inductiveautomation.com/t/try-except-when-reading-tags/16179 "2017-11-30T16:10:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![TruThat](https://avatars.discourse-cdn.com/v4/letter/t/ea666f/32.png) [@TruThat](https://forum.inductiveautomation.com/u/TruThat)\
**Post date:** [November 30, 2017, 4:10pm UTC](https://forum.inductiveautomation.com/t/try-except-when-reading-tags/16179/1 "2017-11-30T16:10:30Z")

</div>

When I am adding some code I would like to wrap it in a try: except:  
I am sure that I just don’t get the concept.

My goal is if I make and error in the code, when it runs the line of code that if it errors it goes it puts a -1 in the Value. and if there is an error with the tag that it does not return “None”

The script console appears to return a “-1” if I mispell the tag. and if the is and error with the tag it returns a “None”  
it never seems to run the except code.

```auto
 try:
    Value = system.tag.read("SLI/Charlotte Emerald/Line 1/Bagger A/Ign_Machine_Running").value
except:
    Value = -99

```

Any pointers would be appreciated.

---

<div class="post-metadata">

**Author:** ![JGJohnson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jgjohnson/32/29582_2.png) [@JGJohnson](https://forum.inductiveautomation.com/u/JGJohnson)\
**Post date:** [November 30, 2017, 4:23pm UTC](https://forum.inductiveautomation.com/t/try-except-when-reading-tags/16179/2 "2017-11-30T16:23:04Z")

</div>

Try running this script in your script console

```auto
value = system.tag.read("thisTagDoesNotExist").value
print value

```

Trying to read a tag that does not exist does not throw an exception.

Instead of using try: except:, you could use system.tag.exists() to check for invalid tags instead.

---

<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:** [November 30, 2017, 4:23pm UTC](https://forum.inductiveautomation.com/t/try-except-when-reading-tags/16179/3 "2017-11-30T16:23:52Z")

</div>

I don’t think system.tag.read() ever throws an exception. It returns a qualified value where the `.quality` property will be relevant if you provide an invalid tag path or whatever. The shortcut to tack `.value` on the end is only appropriate when supplying tested, static tagpaths.

---

<div class="post-metadata">

**Author:** ![TruThat](https://avatars.discourse-cdn.com/v4/letter/t/ea666f/32.png) [@TruThat](https://forum.inductiveautomation.com/u/TruThat)\
**Post date:** [November 30, 2017, 4:30pm UTC](https://forum.inductiveautomation.com/t/try-except-when-reading-tags/16179/4 "2017-11-30T16:30:13Z")

</div>

Thank you pturmel…I thought everything would throw an exception…So that was a big EYE opener for me.
