Make log_error actually return a value.
[matthijs/projects/xerxes.git] / tools / misc.py
index 110c370a74500672c1749dbaf4bb4b9f7c115ae8..ba84f05e87141c0be4a9e2efd14bdf1d906dbc1d 100644 (file)
@@ -13,3 +13,18 @@ def make_iter(value):
         except TypeError:
             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:
+            return func(*args, **kwargs)
+        except Exception, e:
+            import traceback
+            traceback.print_exc()
+            raise e
+    return show