Error manangment during eam.sendRequest

I have a remote agent and it is missing a message handler. This is by design. I will add the message handler later but in the meantime I want to capture the error that the sendRequest throws in the following try/except. However the following does not capture this error like I expect. In this case the error text should log and instead I get the normal pop up with a bunch of red with a clear description that the message handler does not exist on the remote gateway. Is there a way to capture this type of error?

result = None
try:
	result = system.util.sendRequest(project, messageHandler, payload, agent, timeoutSec)
except Exception as e:
	L.warn("An error occured while sending '%s' to '%s'" % (functionName, agent))
	L.warn("Error: %s" % str(e))
return result

This may be a case where you need to catch java.lang.Exception as well:

2 Likes

Nowadays I recommend catching java.lang.Throwable instead of java.lang.Exception. For two reasons:

  • Catch pesky java errors, too.

  • No name conflict with pythons own exception name, so you can from java.lang import Throwable.

4 Likes