topicsconsult other reference resources and manuals version skew notein python xthe older tools sys exc_type and sys exc_value still work to fetch the most recent exception type and valuebut they can manage only singleglobal exception for the entire process these two names have been removed in python the newer and preferred sys exc_info(call available in both and instead keeps track of each thread' exception informationand so is threadspecific of coursethis distinction matters only when using multiple threads in python programs ( subject beyond this book' scope)but forces the issue see other resources for more details exception design tips and gotchas ' lumping design tips and gotchas together in this because it turns out that the most common gotchas largely stem from design issues by and largeexceptions are easy to use in python the real art behind them is in deciding how specific or general your except clauses should be and how much code to wrap up in try statements let' address the second of these concerns first what should be wrapped in principleyou could wrap every statement in your script in its own trybut that would just be silly (the try statements would then need to be wrapped in try statements!what to wrap is really design issue that goes beyond the language itselfand it will become more apparent with use but for nowhere are few rules of thumboperations that commonly fail should generally be wrapped in try statements for exampleoperations that interface with system state (file openssocket callsand the likeare prime candidates for try howeverthere are exceptions to the prior rule--in simple scriptyou may want failures of such operations to kill your program instead of being caught and ignored this is especially true if the failure is showstopper failures in python typically result in useful error messages (not hard crashes)and this is the best outcome some programs could hope for you should implement termination actions in try/finally statements to guarantee their executionunless context manager is available as with/as option the tryfinally statement form allows you to run code whether exceptions occur or not in arbitrary scenarios it is sometimes more convenient to wrap the call to large function in single try statementrather than littering the function itself with many try statements designing with exceptions