Try Except when reading tags

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.

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

Any pointers would be appreciated.

Try running this script in your script console

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.

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.

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