Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
line number of exception
#1
I can get error message printed out how to get the line number at which exceptoin occurred:

try:
    stat = callablePy(mainArgv, instGlobalConfig)
except Exception as errMsg:
    printErr("Exception occurred. ")
    printErr(str(errMsg))
    printErr(str(errMsg.__class__))
    stat = RET_EXCEPT

i am calling another python module from main module as follows, but exception prints out the main module's file and line no. I need to get the called module's file name occurrence and line no how do i do that?
print "importing " + file1
module = __import__(file1)

try:
    callable = getattr(module, "main")
    res = callable( [str(file1), "asd"] )
except Exception as errMsg:
    print "exception!:"
    print errMsg
    print errMsg.__class__
    obj1 = sys.exc_info()
    print obj1[2].tb_lineno
    print dir(obj1)
Reply
#2
The traceback object's tb_next attribute and/or the traceback module might be helpful.
Reply
#3
Use the traceback module?

Edit: Ninja'ed....
Unless noted otherwise, code in my posts should be understood as "coding suggestions", and its use may require more neurones than the two necessary for Ctrl-C/Ctrl-V.
Your one-stop place for all your GIMP needs: gimp-forum.net
Reply
#4
thx it seems working. more question may follow
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Sequential number for rows retrieved and storing the Primary UKey to the line number GYKR 2 571 Aug-22-2023, 10:14 AM
Last Post: GYKR
  line number of first and second occurance of string in a file mdalireza 1 1,823 Nov-18-2019, 09:55 AM
Last Post: perfringo
  Search for the line number corresponding to a value Lali 0 1,637 Oct-22-2019, 08:56 AM
Last Post: Lali
  print number of a list line per line lateublegende 2 2,715 Mar-20-2019, 04:07 PM
Last Post: lateublegende
  Adding a line number to an lxml Element vindy 0 3,337 Mar-08-2019, 08:34 PM
Last Post: vindy
  get the number in the line in text file lateublegende 2 2,474 Jan-29-2019, 06:03 PM
Last Post: lateublegende
  During handling of the above exception, another exception occurred Skaperen 7 26,848 Dec-21-2018, 10:58 AM
Last Post: Gribouillis
  getting the source line number Skaperen 12 7,827 Dec-17-2017, 04:29 AM
Last Post: Skaperen
  getting source line number Skaperen 4 14,234 Feb-27-2017, 06:56 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020