commit message from python script
This commit is contained in:
29
Lehrer/pythonkurs/Mittwoch/utilities.py
Executable file
29
Lehrer/pythonkurs/Mittwoch/utilities.py
Executable file
@@ -0,0 +1,29 @@
|
||||
"""
|
||||
Miscellaneous utilities
|
||||
"""
|
||||
|
||||
import sys
|
||||
from traceback import format_tb
|
||||
# oder print_tb(traceback, file=<handle>)
|
||||
|
||||
|
||||
def hide_exception(func):
|
||||
try:
|
||||
return func()
|
||||
except Exception as e:
|
||||
name = type(e).__name__
|
||||
text = str(e)
|
||||
traceback = ''.join(format_tb(e.__traceback__))
|
||||
if '-V' in sys.argv or '--with-exception' in sys.argv:
|
||||
# Fuer Faule, einfach existierende Exception weiterleiten
|
||||
# raise
|
||||
print("Traceback:\n", traceback, sep='', file=sys.stderr)
|
||||
print("{name}: {text}".format(name=name, text=text), file=sys.stderr)
|
||||
else:
|
||||
print("Interner Fehler,", e)
|
||||
# TODO: Exception-Informationen in Logdatei schreiben
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print("from utilities import hide_exception")
|
||||
print("hide_exception(main)")
|
||||
Reference in New Issue
Block a user