# Gateway Messages and Exceptions

**URL:** <https://forum.inductiveautomation.com/t/gateway-messages-and-exceptions/43428>\
**Category:** Ignition\
**Tags:** ignition80\
**Created:** [February 15, 2021, 6:52pm UTC](https://forum.inductiveautomation.com/t/gateway-messages-and-exceptions/43428 "2021-02-15T18:52:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [February 15, 2021, 6:52pm UTC](https://forum.inductiveautomation.com/t/gateway-messages-and-exceptions/43428/1 "2021-02-15T18:52:16Z")

</div>

First things first.  
Ignition version is 8.1.1

When a remote gateway messageHandler is called and an exception is generated, it seems that the handling between a python exception and a java exception is different. It maybe my lack of understanding though between the two.

If I have a two different messageHandlers in a remote gateway like so:

**pythonException**

```auto
return ValueError('This is an uncaught python exception')

```

and

**javaException**

```auto
import java.lang.Exception
raise java.lang.Exception('This is an uncaught java exception')

```

Then I call the pythonException as follows:

```auto
def onSuccess(message):
	inProgress = False
	if not inProgress:
		inProgress = True
		print 'onSuccess'
		print message
		print type(message)

def onError(message):
	inProgress = False
	if not inProgress:
		inProgress = True
		print 'onError'
		print message
	

reqObj = system.util.sendRequestAsync(
	project='TicketTrackSync',
	messageHandler='pythonException',
	remoteServer='ignition-esp_hcp_whi'
)
reqObj.onSuccess(onSuccess)
reqObj.onError(onError)

```

I end up getting the onSuccess call back:

```auto
>>> onSuccess
This is an uncaught python exception
<type 'exceptions.ValueError'>

```

However if I call the javaException as follows:

```auto
def onSuccess(message):
	inProgress = False
	if not inProgress:
		inProgress = True
		print 'onSuccess'
		print message
		print type(message)

def onError(message):
	inProgress = False
	if not inProgress:
		inProgress = True
		print 'onError'
		print message
	

reqObj = system.util.sendRequestAsync(
	project='TicketTrackSync',
	messageHandler='javaException',
	remoteServer='ignition-esp_hcp_whi'
)
reqObj.onSuccess(onSuccess)
reqObj.onError(onError)

```

I end up getting the onError call back:

```auto
>>> onError
java.lang.Exception: Gateway-side exception: java.lang.Exception: Remote exception: Traceback (most recent call last):
  File "<MessageHandlerScript:TicketTrackSync/javaException >", line 12, in handleMessage
	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

	at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)

	at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)

	at java.base/java.lang.reflect.Constructor.newInstance(Unknown Source)

	at org.python.core.PyReflectedConstructor.constructProxy(PyReflectedConstructor.java:211)

java.lang.Exception: java.lang.Exception: This is an uncaught java exception

```

Is this by design? I’m sending data across to a remote gateway that MAY have issues with a database insert, and I want to make 100% sure that I can capture and report errors that occur. Right now I’m doubling up on the onSuccess and onError call back with checks on the message to make sure that I don’t miss an exception, but it feels like a python exception should also generate the onError rather than just the java one.

---

<div class="post-metadata">

**Author:** ![chi](https://avatars.discourse-cdn.com/v4/letter/c/0ea827/32.png) [@chi](https://forum.inductiveautomation.com/u/chi)\
**Post date:** [February 15, 2021, 7:55pm UTC](https://forum.inductiveautomation.com/t/gateway-messages-and-exceptions/43428/2 "2021-02-15T19:55:18Z")

</div>

> [@bschroeder](#):
>
> **pythonException**
> 
> ```auto
> return ValueError('This is an uncaught python exception')
> 
> ```

You are not raising a Python Exception here but your function simply returns a result of type `ValueError `. Use `raise ValueError...` like you do with the java Exception.

---

<div class="post-metadata">

**Author:** ![bschroeder](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bschroeder/32/13260_2.png) [@bschroeder](https://forum.inductiveautomation.com/u/bschroeder)\
**Post date:** [February 15, 2021, 8:02pm UTC](https://forum.inductiveautomation.com/t/gateway-messages-and-exceptions/43428/3 "2021-02-15T20:02:14Z")

</div>

DOH. I knew I missed something in my validation testing.

Thanks for pointing that out.

When I changed it to raise it is working as I expected
