December 2018
Beginner to intermediate
796 pages
19h 54m
English
We briefly talked about the traceback in Chapter 8, Testing, Profiling, and Dealing with Exceptions, when we saw several different kinds of exceptions. The traceback gives you information about what went wrong in your application. It's helpful to read it, so let's see a small example:
# traceback_simple.pyd = {'some': 'key'}key = 'some-other'print(d[key])
We have a dictionary and we try to access a key that isn't in it. You should remember that this will raise a KeyError exception. Let's run the code:
$ python traceback_simple.pyTraceback (most recent call last): File "traceback_simple.py", line 3, in <module> print(d[key])KeyError: 'some-other'
You can see that we get all the information we need: the module name, ...
Read now
Unlock full access