| 1 | # Contributed by Max Rabkin, 2008 |
| 2 | # With this installed python exceptions will be reported through the |
| 3 | # fontforge user interface and not to stderr. |
| 4 | |
| 5 | import sys |
| 6 | import traceback |
| 7 | import fontforge |
| 8 | |
| 9 | def excepthook (*args): |
| 10 | tb = ''.join(traceback.format_exception(*args)) |
| 11 | message = ''.join(traceback.format_exception_only(*args[:2])).strip() |
| 12 | |
| 13 | fontforge.logWarning(tb.replace('%', '%%')) |
| 14 | fontforge.postError('Unhandled exception', |
| 15 | message.replace('%','%%')) |
| 16 | |
| 17 | if fontforge.hasUserInterface(): |
| 18 | # only install the hook if this session has UI |
| 19 | sys.excepthook = excepthook |