debuggingtestingand profiling or one of our own modules listed the problem will almost certainly be on the line python specifiesor on an earlier line this particular example illustrates that we should modify the blocks py program to cope gracefully when given the names of nonexistent files this is usability errorand it should also be classified as logical errorsince terminating and printing traceback cannot be considered to be acceptable program behavior in factas matter of good policy and courtesy to our userswe should always catch all relevant exceptionsidentifying the specific ones that we consider to be possiblesuch as environmenterror in generalwe should not use the catchalls of exceptor except exception:although using the latter at the top level of our program to avoid crashes might be appropriate--but only if we always report any exceptions it catches so that they don' go silently unnoticed exceptions that we catch and cannot recover from should be reported in the form of error messagesrather than exposing our users to tracebacks which look scary to the uninitiated for gui programs the same appliesexcept that normally we would use message box to notify the user of problem and for server programs that normally run unattendedwe should write the error message to the server' log python' exception hierarchy was designed so that catching exception doesn' quite cover all the exceptions in particularit does not catch the keyboardinterrupt exceptionso for console applications if the user presses ctrl+cthe program will terminate if we choose to catch this exceptionthere is risk that we could lock the user into program that they cannot terminate this arises because bug in our exception handling code might prevent the program from terminating or the exception propagating (of courseeven an "uninterruptibleprogram can have its process killedbut not all users know how so if we do catch the keyboardinterrupt exception we must be extremely careful to do the minimum amount of saving and clean up that is necessary--and then terminate the program and for programs that don' need to save or clean upit is best not to catch keyboardinterrupt at alland just let the program terminate one of python ' great virtues is that it makes clear distinction between raw bytes and strings howeverthis can sometimes lead to unexpected exceptions occurring when we pass bytes object where str is expected or vice versa for exampletraceback (most recent call last)file "program py"line in print(datetime datetime strptime(dateformat)typeerrorstrptime(argument must be strnot bytes when we hit problem like this we can either perform the conversion--in this caseby passing date decode("utf ")--or carefully work back to find out where