3 ms·
Java had this feature since the last millenium (java 1.3, i think). I really miss it programming in python 2.7.
by aurelianito 11y ago
Java had this feature since the last millenium (java 1.3, i think). I really miss it programming in python 2.7.
- MrBuddyCasino 11y agoFor anyone wondering: its chained exceptions.
- Latty 11y agoPython's is actually a little nicer too, in 3.x - it has two types of chains, the 'root cause' one like Java, and a 'this is what I was handling when this exception happened' - to stop an error in your exception handling code hide the original error.
- pacofvf 11y agoby reading this I just learned about the concept of chained exceptions, although I can't see why is so useful, the built-in traceback and sys module has always been good enough: import sys,traceback try: ... except Exception as ex: exc_type, exc_value, exc_traceback = sys.exc_info() logger.error("%s:%s" % (str(ex), str(traceback.format_exception(exc_type, exc_value, exc_traceback)))) raise MyException(" :( ")
- baq 11y agothat's not nearly good enough, it's barely acceptable. i've been programming python for a decade and the fact you have to do this with exceptions was plainly dumb. as a programmer you should never have to worry about preserving tracebacks.