> For older Python versions please see http://blog.ianbicking.org/2007/09/12/re-raising-exceptions/
This is super important, I recently rediscovered this with a colleague (the company's tool was fucking up exceptions everywhere, either over-logging things or throwing stacktraces out in an attempt to rewrap them and we decided to fix this).
Although the second-to-last example:
new_exc = Exception("Error in line %s: %s"
% (lineno, exc or exc_class))
raise new_exc.__class__, new_exc, tb
would be much better written as: raise Exception, "Error in line %s: %s" % (lineno, exc or exc_class), tb
For older Python versions please see http://blog.ianbicking.org/2007/09/12/re-raising-exceptions/