How to get the script line number when an exception occurs #491
-
Hello, When running a python script in background without TPythonGUIInputOutput, it's difficult to debug when exception occurs. In this case, how to get the stacktrace/line number? Thank you |
Beta Was this translation helpful? Give feedback.
Answered by
pyscripter
Dec 16, 2024
Replies: 1 comment 1 reply
-
When you execute code, say with ExecString, CheckError is called at the end which on exception updates PythoneEngine.Traceback. and raises a suitable EPythonError descendent exception. type
EPythonError = class(Exception)
public
EName : string;
EValue : string;
end;
TTracebackItem = class
public
FileName : string;
LineNo : Integer;
Context : string;
end;
TPythonTraceback = class
public
property ItemCount : Integer read GetItemCount;
property Items[ idx : Integer ] : TTracebackItem read GetItem;
property Limit : Integer read FLimit write FLimit;
end; So what you typically do is: try
ExecString(Code, FileName);
except
on E: EPythonError do
begin
// Inspect E.EName and E.EValue
// Inspect the GetPythonEngine.Traceback
end;
end |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
chicknsoup
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When you execute code, say with ExecString, CheckError is called at the end which on exception updates PythoneEngine.Traceback. and raises a suitable EPythonError descendent exception.
So what you typically do is: