# Way to allow Send Report for custom errors?

**URL:** <https://forum.inductiveautomation.com/t/way-to-allow-send-report-for-custom-errors/31785>\
**Category:** Ignition\
**Tags:** ignition80\
**Created:** [January 30, 2020, 5:49pm UTC](https://forum.inductiveautomation.com/t/way-to-allow-send-report-for-custom-errors/31785 "2020-01-30T17:49:35Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [January 30, 2020, 5:49pm UTC](https://forum.inductiveautomation.com/t/way-to-allow-send-report-for-custom-errors/31785/1 "2020-01-30T17:49:35Z")

</div>

I’ve been refactoring my project heavily with a large addition being error try/catching.

I previously had set up the Igntition error reports to be sent to me so when someone sees the red box of death they can email me the error stack.

Is there a way to do that with my custom errors? Some way to enable system.gui functons to be able to send reports to the same address listed on the gateway?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [January 30, 2020, 6:21pm UTC](https://forum.inductiveautomation.com/t/way-to-allow-send-report-for-custom-errors/31785/2 "2020-01-30T18:21:05Z")

</div>

You can import ErrorUtil and call showError; eg:

```auto
from com.inductiveautomation.ignition.client.util.gui import ErrorUtil
try:
    <some python code>
except ValueError as e:
    ErrorUtil.showError("Something went wrong", e)

```

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [January 30, 2020, 7:43pm UTC](https://forum.inductiveautomation.com/t/way-to-allow-send-report-for-custom-errors/31785/3 "2020-01-30T19:43:31Z")

</div>

Hm almost. I did this to cause an error in a button on click extenstion.

```auto
from com.inductiveautomation.ignition.client.util.gui import ErrorUtil
try:
	len(something)
except Exception, e:
	ErrorUtil.showError("Some Error happened", str(e))

```

And I get this  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/5/53dc3fff45cafeabfbd93443206bbd7ccdadff79.png)  
But I can’t click details and therefore cannot send report.

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [January 30, 2020, 7:50pm UTC](https://forum.inductiveautomation.com/t/way-to-allow-send-report-for-custom-errors/31785/4 "2020-01-30T19:50:45Z")

</div>

By using the (String, String) overload instead of the (String, Throwable) overload, you put the error info into the title.

Try the version Paul suggested, without stringifying the error.

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [January 30, 2020, 7:58pm UTC](https://forum.inductiveautomation.com/t/way-to-allow-send-report-for-custom-errors/31785/5 "2020-01-30T19:58:34Z")

</div>

Ok that got me closer but only becuase it seems to actually be causing an error within ErrorUtil.

My current code

```auto
from com.inductiveautomation.ignition.client.util.gui import ErrorUtil
try:
    len(nonExistantVariable)
except Exception as e:
    ErrorUtil.showError("Something went wrong", e)

```

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/b/b65bfb1eea3838dadd722cef13a60627af94afe3.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/8/8a9aae70d44294e008acada418655865947e4efc.png)

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [January 30, 2020, 8:02pm UTC](https://forum.inductiveautomation.com/t/way-to-allow-send-report-for-custom-errors/31785/6 "2020-01-30T20:02:46Z")

</div>

Think I had to do this -

```auto
from com.inductiveautomation.ignition.client.util.gui import ErrorUtil
import java.lang.Exception
try:
    len(nonExistantVariable)
except java.lang.Exception as e:
    ErrorUtil.showError("Something went wrong", e)a

```

But then I don’t see that “Something went wrong” error message anywhere.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/f/f4849c019e576734f4e7400b25b9edd324eea75b.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/2X/a/a3844a2c6ff0cbf4e3ad573a1b732ffa1f1908ab.png)

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [January 30, 2020, 8:30pm UTC](https://forum.inductiveautomation.com/t/way-to-allow-send-report-for-custom-errors/31785/7 "2020-01-30T20:30:49Z")

</div>

You need to coerce the Python exception back into a Java exception to pass it into ErrorUtil. Something like this:

```auto
import java.lang.Exception
from org.python.core import Py, PyObject
from com.inductiveautomation.ignition.client.util.gui import ErrorUtil

try:
    len(nonExistantVariable)
except (java.lang.Exception, Exception) as e:
	if (isinstance(e, PyObject)):
		e = Py.makeException(pye)
	ErrorUtil.showError("Something else went wrong", e)

```

For bonus usage points, since Ignition 8 is using Jython 2.7, you can use a context manager:

```auto
class ErrorHandler:
	def __init__ (self, message = "Something went wrong"):
		self.message = message
		
	def __enter__ (self):
		return self
		
	def __exit__ (self, exc_type, exc_value, traceback):
		if (isinstance(exc_type, PyObject)):
			exc_value = Py.makeException(exc_value)
		ErrorUtil.showError(self.message, exc_value)

```

In use:

```auto
with ErrorHandler("Unexpected Error"):
	len(nonexistent)

```

So you don’t have to write your try/catch and import statements each time - you can just have your context manager defined in a project library.
