John_Sheares
John_Sheares

Reputation: 1414

How to use TracebackDelegate payload when exception occurs with ScriptEngine.SetTrace()?

I am using ScriptEngine.SetTrace() and I am wondering how do you use the tuple that is contained in the TracebackDelegate "payload" variable when an exception occurs? I would like to get the message, method name, line number, file name, etc for the exception. I could get the last three from frame.f_code and frame.f_lineno, but the other information seems to be contained in the payload tuple object, which I have no idea how to extract.

Upvotes: 1

Views: 411

Answers (1)

John_Sheares
John_Sheares

Reputation: 1414

Nevermind, I have figured it out:

PythonTuple tuple = (PythonTuple)payload;
string err = PythonType.Get__name__((PythonType)tuple[0]);
PythonExceptions.BaseException e = (PythonExceptions.BaseException)tuple[1];
TraceBack tb = (TraceBack)tuple[2];
Debug.WriteLine(err + " " + e.clsException.Message);

Upvotes: 1

Related Questions