Skip to content

How to get the script line number when an exception occurs #491

Closed Answered by pyscripter
chicknsoup asked this question in Q&A
Discussion options

You must be logged in to vote

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

Comment options

You must be logged in to vote
1 reply
@chicknsoup
Comment options

Answer selected by chicknsoup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy