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


Messages In This Thread
line number of exception - by ggpf000 - Nov-28-2016, 10:45 PM
RE: line number of exception - by stranac - Nov-29-2016, 08:26 AM
RE: line number of exception - by Ofnuts - Nov-29-2016, 08:37 AM
RE: line number of exception - by ggpf000 - Nov-30-2016, 12:43 AM

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 608 Aug-22-2023, 10:14 AM
Last Post: GYKR
  line number of first and second occurance of string in a file mdalireza 1 1,859 Nov-18-2019, 09:55 AM
Last Post: perfringo
  Search for the line number corresponding to a value Lali 0 1,665 Oct-22-2019, 08:56 AM
Last Post: Lali
  print number of a list line per line lateublegende 2 2,744 Mar-20-2019, 04:07 PM
Last Post: lateublegende
  Adding a line number to an lxml Element vindy 0 3,394 Mar-08-2019, 08:34 PM
Last Post: vindy
  get the number in the line in text file lateublegende 2 2,522 Jan-29-2019, 06:03 PM
Last Post: lateublegende
  During handling of the above exception, another exception occurred Skaperen 7 26,957 Dec-21-2018, 10:58 AM
Last Post: Gribouillis
  getting the source line number Skaperen 12 7,937 Dec-17-2017, 04:29 AM
Last Post: Skaperen
  getting source line number Skaperen 4 14,362 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