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
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
Thanks to Stack Overflow for teaching me this!