From: Matthijs Kooijman Date: Fri, 31 Oct 2008 16:30:34 +0000 (+0100) Subject: Add log_error decorator for debugging. X-Git-Url: https://git.stderr.nl/gitweb?a=commitdiff_plain;h=dec5a89fa614023c3e9fe7b0eff52eb186832f70;p=matthijs%2Fprojects%2Fxerxes.git Add log_error decorator for debugging. --- diff --git a/tools/misc.py b/tools/misc.py index 1edf472..1259ab7 100644 --- a/tools/misc.py +++ b/tools/misc.py @@ -14,3 +14,17 @@ def make_iter(value): pass return [value] # vim: set sts=4 sw=4 expandtab: + +""" +Decarator that catches any exception raised by the decorated function, +prints it to stdout and raises it again. +""" +def log_error(func): + def show(*args, **kwargs): + try: + func(*args, **kwargs) + except Exception, e: + import traceback + traceback.print_exc() + raise e + return show