Add log_error decorator for debugging.
authorMatthijs Kooijman <matthijs@stdin.nl>
Fri, 31 Oct 2008 16:30:34 +0000 (17:30 +0100)
committerMatthijs Kooijman <matthijs@stdin.nl>
Fri, 31 Oct 2008 16:30:34 +0000 (17:30 +0100)
tools/misc.py

index 1edf4725f59ad248f3f28ac11f87819cf54b74d4..1259ab7d706284e6abc2164e79d6d90cdbe50143 100644 (file)
@@ -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