debuggingtestingand profiling exceptionour ownplus the one in err if the invaliddataerror exception is raised and not caughtthe resulting traceback will look something like thistraceback (most recent call last)file "application py"line in process int(datavalueerrorinvalid literal for int(with base ' the above exception was the direct cause of the following exceptiontraceback (most recent call last)file "application py"line in print(process(line)file "application py"line in process raise invaliddataerror("invalid data received"from err __main__ invaliddataerrorinvalid data received at the bottom our custom exception and text explain what the problem iswith the lines above them showing where the exception was raised (line )and where it was caused (line but we can also go back furtherinto the chained exception which gives more details about the specific errorand which shows the line that triggered the exception ( for detailed rationale and further information about chained exceptionssee pep scientific debugging |if our program runs but does not have the expected or desired behavior then we have bug-- logical error--that we must eliminate the best way to eliminate such errors is to prevent them from occurring in the first place by using tdd (test driven developmenthoweversome bugs will always get throughso even with tdddebugging is still necessary skill to learn in this subsection we will outline an approach to debugging based on the scientific method the approach is explained in sufficient detail that it might appear to be too much work for tackling "simplebug howeverby consciously following the process we will avoid wasting time with "randomdebuggingand after awhile we will internalize the process so that we can do it unconsciouslyand therefore very quickly to be able to kill bug we must be able to do the following reproduce the bug locate the bug the ideas used in this subsection were inspired by the debugging in the book code complete by steve mcconnellisbn