Today I learnt why pdb can't access an exception ๐
I like to use pdb
for debugging in Python, Iโd noticed when using it to debug exceptions I canโt always access the exception. Take the following code:
If you run it and try and inspect the value of err
youโll see *** NameError: name 'err' is not defined
. Why is this? ๐ค
The exception is only within scope in the try
except
block, if the call to pdb.set_trace()
is the last line then the block has been closed when we enter the debugger.
A simple way to get round this is to add a pass
after the pdb
call.
Thanks to Stack Overflow for teaching me this!
https://stackoverflow.com/questions/38672560/why-cant-pdb-access-a-variable-containing-an-exception
https://stackoverflow.com/questions/62796591/breakpoint-in-except-clause-doesnt-have-access-to-the-bound-exception