[Frugalware-darcs] vmexam: python/exception_handler.py: import

VMiklos vmiklos at frugalware.org
Tue Jun 26 16:56:23 CEST 2007


Darcsweb-Url: http://darcs.frugalware.org/darcsweb/darcsweb.cgi?r=vmexam;a=darcs_commitdiff;h=20070626145232-e2957-692447e92487ce4b8140bf07876a3f9e575329e5.gz;

[python/exception_handler.py: import
VMiklos <vmiklos at frugalware.org>**20070626145232] {
addfile ./python/exception_handler.py
hunk ./python/exception_handler.py 1
+import traceback, inspect, sys
+
+def foo():
+	1/0
+
+def on_bug():
+	# Python style
+	type, value, tb = sys.exc_info()
+	stype = str(type).split("'")[1]
+	print "Traceback (most recent call last):"
+	print "".join(traceback.format_tb(tb)).strip()
+	print "%s: %s" % (stype, value)
+
+	# ~ C style
+	badline = inspect.trace()[-1]
+	print "%s at file %s line %d" % (stype, badline[1], badline[2])
+
+print "foo"
+try:
+	foo()
+except Exception:
+	on_bug()
+print "bar"
}


More information about the Frugalware-darcs mailing list