to analyze we do this by storing the names of the files we want to analyze in listand then we call count_words(for each file in the list we'll try to count the words for alice in wonderlandsiddharthamoby dickand little womenwhich are all available in the public domain 've intentionally left siddhartha txt out of the directory containing word_count pyso we can see how well our program handles missing filedef count_words(filename)--snip-filenames ['alice txt''siddhartha txt''moby_dick txt''little_women txt'for filename in filenamescount_words(filenamethe missing siddhartha txt file has no effect on the rest of the program' executionthe file alice txt has about words sorrythe file siddhartha txt does not exist the file moby_dick txt has about words the file little_women txt has about words using the tryexcept block in this example provides two significant advantages we prevent our users from seeing tracebackand we let the program continue analyzing the texts it' able to find if we don' catch the filenotfounderror that siddhartha txt raisedthe user would see full tracebackand the program would stop running after trying to analyze siddhartha it would never analyze moby dick or little women failing silently in the previous examplewe informed our users that one of the files was unavailable but you don' need to report every exception you catch sometimes you'll want the program to fail silently when an exception occurs and continue on as if nothing happened to make program fail silentlyyou write try block as usualbut you explicitly tell python to do nothing in the except block python has pass statement that tells it to do nothing in blockdef count_words(filename)"""count the approximate number of words in file ""try--snip-except filenotfounderroru pass else--snip-filenames ['alice txt''siddhartha txt''moby_dick txt''little_women txt'for filename in filenamescount_words(filename