Skip to content

Python exception formatting #1771

@mole99

Description

@mole99

Hi Matthias!

I often use KLayout together with Python (which is a great combination!), but one point that could be improved are the error messages. KLayout prints the error message, but not where it comes from.

I haven't yet been able to figure out in the codebase where the exceptions are being printed. I assume you use a try/except each time you call user code to catch all exceptions and print them as follows:

try:
    1/0
except Exception as e:
    print(e)

Is this correct?

If you use the traceback module, you can print the exception in the same format as the default handler does:

import traceback

try:
    1/0
except Exception:
    traceback.print_exc()

Maybe this could be used in KLayout?

Leo

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions