Python exception handling - emailing traceback and context

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… :confused:), 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

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.

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

But can you not do this :

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 ?