try/finally block when an exception occurs insteadpython jumps back to run the finally actionand then propagates the exception up to prior handler (in this caseto the default handler at the topif we change the call inside this function so as not to trigger an exceptionthe finally code still runsbut the program continues after the trydef after()tryfetcher( finallyprint('after fetch'print('after try?'after(after fetch after tryin practicetry/except combinations are useful for catching and recovering from exceptionsand try/finally combinations come in handy to guarantee that termination actions will fire regardless of any exceptions that may occur in the try block' code for instanceyou might use try/except to catch errors raised by code that you import from third-party libraryand try/finally to ensure that calls to close files or terminate server connections are always run we'll see some such practical examples later in this part of the book although they serve conceptually distinct purposesas of python we can mix except and finally clauses in the same try statement--the finally is run on the way out regardless of whether an exception was raisedand regardless of whether the exception was caught by an except clause as we'll learn in the next python and both provide an alternative to try/finally when using some types of objects the with/as statement runs an object' context management logic to guarantee that termination actions occurirrespective of any exceptions in its nested blockwith open('lumberjack txt'' 'as filefile write('the larch!\ 'always close file on exit although this option requires fewer lines of codeit' applicable only when processing certain object typesso try/finally is more general termination structureand is often simpler than coding class in cases where with is not already supported on the other handwith/as may also run startup actions tooand supports user-defined context management code with access to python' full oop toolset why you will careerror checks one way to see how exceptions are useful is to compare coding styles in python and languages without exceptions for instanceif you want to write robust programs in the languageyou generally have to test return values or status codes after every exception basics