-
-
Couldn't load subscription status.
- Fork 324
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.
All reactions
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 ...
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.
All reactions
-
👍 2
-
Thank you.
Beta Was this translation helpful? Give feedback.