Version 8.1.19
I have a script running:
if record is None:
Exit()
The script does exit, but the script also throws an error saying Exit undefined.
What is the correct exit?
Version 8.1.19
I have a script running:
if record is None:
Exit()
The script does exit, but the script also throws an error saying Exit undefined.
What is the correct exit?
I always use return where possible. Luckily, all perspective events are setup as def
functions, so you can just return
to exit the script. When I did use exit()
it was
import sys
sys.exit()
Could you tell me the difference and advantage?
sys.exit()
and the Java equivalent aren't designed to return early from a method, they're designed to end the execution of the program, and the only reason your Ignition Gateway / JVM doesn't cease to exist after that is because we've hooked into prevent it.
It's not meant for what you're using it for.
Does that mean Return is best?
Yes, return, or in some weird contexts where you can't just return, guard your logic with some kind of condition.
In your original example, it would just be:
if record is not None:
# do logic
Careful! It's return
.