How can I get the line number of error

I try to make that coding on OpenMV with touch screen with out computer.I have finished many jobs.But I met a problem. I have tryed to use ‘try/except’ ot get the error.But it cant tell the line number of error. I see the 'traceback' information in IDE.But I cant import it in codes.Is there any way to get line number of error?

I almost tried every way that I can found. But not a single one can work. The ‘tracework‘ seems to be the most reliable way. But it can’t import on OpenMV. Is it removed on OpenMV?Do you know any code to replace it?

Exception objects in python 3 include the line number. It’s literal printed in the ide terminal. This information is there.

Screenshot
You see,I am making a local programming environment like this with out computer.But I can`t get error line in it.I saw error line information in IDE.So is there any way I can get it in local program?

You’ll have to parse the output. The exception object doesn’t make that info available to the Python side.

Is there a way in micropython to capture the error/line number into a variable for parsing?

Use pythons exception system.

The exception object in micropython does not return the line number for me even on the most recent version of OpenMV. I was able to access the line number with the following snippet.

    def get_exception(err) -> str:
          buf = io.StringIO()
          sys.print_exception(err, buf)
          return buf.getvalue()

Isn’t the exception line number printed by the IDE?

it is printed but it is not accessible in the error object and cannot be assigned to a variable. When you try to assign it, the error gets printed (even without a print statement) and the variable is set to “”