# Question about Exit()

**URL:** <https://forum.inductiveautomation.com/t/question-about-exit/74731>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [June 7, 2023, 6:21pm UTC](https://forum.inductiveautomation.com/t/question-about-exit/74731 "2023-06-07T18:21:45Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [June 7, 2023, 6:21pm UTC](https://forum.inductiveautomation.com/t/question-about-exit/74731/1 "2023-06-07T18:21:45Z")

</div>

Version 8.1.19  
I have a script running:

```auto
if record is None:
   Exit()

```

The script does exit, but the script also throws an error saying Exit undefined.  
What is the correct exit?

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [June 7, 2023, 6:31pm UTC](https://forum.inductiveautomation.com/t/question-about-exit/74731/2 "2023-06-07T18:31:42Z")

</div>

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

```auto
import sys
sys.exit()

```

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [June 7, 2023, 6:35pm UTC](https://forum.inductiveautomation.com/t/question-about-exit/74731/3 "2023-06-07T18:35:08Z")

</div>

Could you tell me the difference and advantage?

---

<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:** [June 7, 2023, 6:37pm UTC](https://forum.inductiveautomation.com/t/question-about-exit/74731/4 "2023-06-07T18:37:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![zacharyw.larson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/zacharyw.larson/32/23749_2.png) [@zacharyw.larson](https://forum.inductiveautomation.com/u/zacharyw.larson)\
**Post date:** [June 7, 2023, 6:42pm UTC](https://forum.inductiveautomation.com/t/question-about-exit/74731/5 "2023-06-07T18:42:11Z")

</div>

Does that mean Return is best?

---

<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:** [June 7, 2023, 6:42pm UTC](https://forum.inductiveautomation.com/t/question-about-exit/74731/6 "2023-06-07T18:42:46Z")

</div>

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:

```auto
if record is not None:
  # do logic

```

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [June 7, 2023, 6:44pm UTC](https://forum.inductiveautomation.com/t/question-about-exit/74731/7 "2023-06-07T18:44:56Z")

</div>

> [@zacharyw.larson](#):
>
> Does that mean Return is best?

Careful! It's `return`.
