January 2019
Beginner
318 pages
8h 23m
English
In this section, we are going to understand analyzing exceptions. Every exception that occurs must be handled. Your log files should also contain few exceptions. If you are getting similar types of exceptions a number of times, then your program has some issue and you should make the necessary changes as soon as possible.
Consider the following example:
f = open('logfile', 'r')print(f.read())f.close()
After running the program, you get the output as follows:
Traceback (most recent call last): File "sample.py", line 1, in <module> f = open('logfile', 'r')FileNotFoundError: [Errno 2] No such file or directory: 'logfile'
In this example, we are trying to read a file that is not present in our directory and as a result it ...
Read now
Unlock full access