3 ms·
Python specific advice on re-raising upon catching and keeping the original trace: in Python 2.7+, please use chained exceptions: http://www.python.org/dev/peps
by praptak 14y ago
Python specific advice on re-raising upon catching and keeping the original trace: in Python 2.7+, please use chained exceptions: http://www.python.org/dev/peps/pep-3134/ http://www.python.org/dev/peps/pep-3134/
For older Python versions please see http://blog.ianbicking.org/2007/09/12/re-raising-exceptions/ http://blog.ianbicking.org/2007/09/12/re-raising-exceptions/
- masklinn 14y ago> For older Python versions please see http://blog.ianbicking.org/2007/09/12/re-raising-exceptions/ 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