# Problem with user defined exceptions

**URL:** <https://forum.inductiveautomation.com/t/problem-with-user-defined-exceptions/96355>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [September 24, 2024, 12:33pm UTC](https://forum.inductiveautomation.com/t/problem-with-user-defined-exceptions/96355 "2024-09-24T12:33:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![steve\_r](https://avatars.discourse-cdn.com/v4/letter/s/58956e/32.png) [@steve\_r](https://forum.inductiveautomation.com/u/steve_r)\
**Post date:** [September 24, 2024, 12:33pm UTC](https://forum.inductiveautomation.com/t/problem-with-user-defined-exceptions/96355/1 "2024-09-24T12:33:34Z")

</div>

I'm noticing a problem with user defined exceptions depending on designer vs gateway scope.

This is the production code in question:

```python
	if is_property_name_thing_one(property_name):
		logger.infof("its a thing one")
		try:
			logger.infof("trying to get it")
			...
		except Shared.exceptions.LotNotFoundException:
			logger.infof("going to import thing one")
			...
		except Exception as e:
			logger.errorf(traceback.format_exc())
			logger.errorf("e type: [%s]" % type(e))
			raise e

```

I'm trying to write tests that exercises this code. When I run the test code via a perspective button press, I get the following in the logs:

```python
run_random_work_order_test	24Sep2024 08:15:39	its a thing one
run_random_work_order_test	24Sep2024 08:15:39	trying to get it
run_random_work_order_test	24Sep2024 08:15:39	going to import thing one

```

When I run the test code via the script console, I get the following in the logs:

```python
08:16:14.320 [SwingWorker-pool-1-thread-10] INFO run_random_work_order_test - its a thing one
08:16:14.321 [SwingWorker-pool-1-thread-10] INFO run_random_work_order_test - trying to get it
08:16:14.382 [SwingWorker-pool-1-thread-10] ERROR run_random_work_order_test - Traceback [the-trace-back]
08:16:14.383 [SwingWorker-pool-1-thread-10] ERROR run_random_work_order_test - e type: [<class 'exceptions.LotNotFoundException'>]

```

I've consistently seen this behavior when doing testing via the script console and in my tests have started to get the string of the error type and doing a string comparison in my tests, but I'm unwilling to alter production code to get around this problem. Any help or info would be greatly appreciated. Thanks.

---

<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:** [September 24, 2024, 12:48pm UTC](https://forum.inductiveautomation.com/t/problem-with-user-defined-exceptions/96355/2 "2024-09-24T12:48:52Z")

</div>

The designer script console is not compatible with Perspective scope for anything but trivial code. Use a button action or similar to test from within Perspective.

---

<div class="post-metadata">

**Author:** ![steve\_r](https://avatars.discourse-cdn.com/v4/letter/s/58956e/32.png) [@steve\_r](https://forum.inductiveautomation.com/u/steve_r)\
**Post date:** [September 24, 2024, 1:37pm UTC](https://forum.inductiveautomation.com/t/problem-with-user-defined-exceptions/96355/3 "2024-09-24T13:37:28Z")

</div>

Understanding why that's the case technically will be helpful to ensure I don't continue to make the same general mistake in a different form.

Why is the script console so drastically different to the point where it shouldn't be used for anything more than a Python REPL?

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [September 24, 2024, 1:50pm UTC](https://forum.inductiveautomation.com/t/problem-with-user-defined-exceptions/96355/4 "2024-09-24T13:50:07Z")

</div>

> [@steve\_r](#):
>
> Why is the script console so drastically different to the point where it shouldn't be used for anything more than a Python REPL?

Only for perspective.

The script console runs in Designer Scope, which is a variant of Vision Client scope, which I hope you can see is completely different from Perspective.

Perspective runs in a Gateway Scope, everything you do in perspective is run on the gateway. For some things which are not specific to a particular Ignition Scoping, the script console is great for testing. But when it comes to things that are specific to any scope other than Vision Client scope (and really even that has some restrictions), its just not compatible. It can lead you astray making you think that the code you've developed works, but then in application it doesn't work because for instance functions are expecting a different signature. There are various other gotchas as well.

Use a Gateway Message Handler, button action, or other type of perspective scripting to force the code execution into the correct scope.

When looking in the manual, pay attention to what scopes a function is available in, this will let you know what signature should be used or if the function is even available to perspective.

---

<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:** [September 24, 2024, 1:56pm UTC](https://forum.inductiveautomation.com/t/problem-with-user-defined-exceptions/96355/5 "2024-09-24T13:56:07Z")

</div>

> [@lrose](#):
>
> Use a Gateway Message Handler, ....

If you have the luxury of using 3rd party modules, you might find this helpful:

The [@system.util.runInGateway](https://www.automation-pros.com/toolkit/doc/utility.html#runingateway) decorator from the Integration Toolkit module.
