Use sys.exc_info() properly

The traceback returned in sys.exc_info()[2] has a reference to the
locals of the functions on the call stack. This can potentially create a
convoluted reference cycle, meaning it is an antipattern to assign the
traceback to a local variable unnecessarily.