again in such as the pdb standard library module examplecatching built-in exceptions python' default exception handling is often exactly what you want--especially for code in top-level script filean error often should terminate your program immediately for many programsthere is no need to be more specific about errors in your code sometimesthoughyou'll want to catch errors and recover from them instead if you don' want your program terminated when python raises an exceptionsimply catch it by wrapping the program logic in try this is an important capability for programs such as network serverswhich must keep running persistently for examplethe following codein the file kaboom pycatches and recovers from the typeerror python raises immediately when you try to concatenate list and string (rememberthe operator expects the same sequence type on both sides)def kaboom(xy)print( ytrigger typeerror trykaboom([ ]'spam'except typeerrorprint('hello world!'print('resuming here'catch and recover here continue here if exception or not when the exception occurs in the function kaboomcontrol jumps to the try statement' except clausewhich prints message since an exception is "deadafter it' been caught like thisthe program continues executing below the try rather than being terminated by python in effectthe code processes and clears the errorand your script recoverspython kaboom py hello worldresuming here keep in mind that once you've caught an errorcontrol resumes at the place where you caught it ( after the try)there is no direct way to go back to the place where the exception occurred (herein the function kaboomin sensethis makes exceptions more like simple jumps than function calls--there is no way to return to the code that triggered the error the try/finally statement the other flavor of the try statement is specialization that has to do with finalization ( terminationactions if finally clause is included in trypython will always run its block of statements "on the way outof the try statementwhether an exception occurred while the try block was running or not its general form is exception coding details