# Python exception handling - emailing traceback and context

**URL:** <https://forum.inductiveautomation.com/t/python-exception-handling-emailing-traceback-and-context/36806>\
**Category:** Ignition\
**Created:** [July 17, 2020, 3:25am UTC](https://forum.inductiveautomation.com/t/python-exception-handling-emailing-traceback-and-context/36806 "2020-07-17T03:25:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [July 17, 2020, 3:25am UTC](https://forum.inductiveautomation.com/t/python-exception-handling-emailing-traceback-and-context/36806/1 "2020-07-17T03:25:26Z")

</div>

v7.9.14  
I have a function that I’ve changed (added in more mandatory arguments), and I’m not sure if I’ve modified every call to it in my project (since you can’t find and replace within global templates… 😕), so I want to raise an exception which i’ll handle by sending the traceback **and context** to me via email, in case an operator stumbles upon one that I potentially have missed. I’ve set default values to these extra arguments in the meantime so that the function will actually run to check and send the error.

I can get the traceback (not actually that useful in this instance), but I don’t know how to get the **context** of it so that I know what Window and component they called the script from.  
How do I retrieve the context?

Notes:

- the function is defined in a shared script library
- the function doesn’t and didn’t previously accept the `event`, so I can’t use `system.gui.getParentWindow`

---

<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:** [July 17, 2020, 12:16pm UTC](https://forum.inductiveautomation.com/t/python-exception-handling-emailing-traceback-and-context/36806/2 "2020-07-17T12:16:15Z")

</div>

I don’t think you can.

I would capture the python call stack and convert it to a java exception (see my later.py). Then attach that as the cause of a new java RuntimeException and raise that for the operator. Include instructions in that to use Ignition’s error e-mail feature to send it to you instead of IA.

---

<div class="post-metadata">

**Author:** ![kaushik.shah](https://avatars.discourse-cdn.com/v4/letter/k/34f0e0/32.png) [@kaushik.shah](https://forum.inductiveautomation.com/u/kaushik.shah)\
**Post date:** [July 17, 2020, 6:36pm UTC](https://forum.inductiveautomation.com/t/python-exception-handling-emailing-traceback-and-context/36806/3 "2020-07-17T18:36:22Z")

</div>

I don’t know if I am interpreting this correctly or not,

But can you not do this :

```auto
import sys
import traceback
	
def myFunc(Var1, Var2):
	try:
         print int(Var1)*int(Var2)
   	except:
		exc_type, exc_obj,tb = sys.exc_info()
		f = tb.tb_frame
		lineno = tb.tb_lineno
		print str(exc_obj) + ' on line number ' + str(lineno)
		
myFunc('h','h')
   	

```

This prints - **invalid literal for int() with base 10: h on line number 6**

On the above function can you just not pass the exc\_obj as a parameter to another function which just emails you the exc\_obj as a body message ?
