Anton Tarasenko
Anton Tarasenko

Reputation: 8455

How to print Python variables after an error in PyCharm?

When a script ends with an error during debugging, PyCharm got disconnected from pydev. So, the state of variable at the moment of the error remains unknown.

How can I find out the very latest values of variables right before the error happens?

Updated: This problem arises only when you try to debug a unit test. You have to check "Activation policy: On raise" for "All Breakpoints" in the list of breakpoints.

Upvotes: 2

Views: 2956

Answers (1)

TidB
TidB

Reputation: 1759

The simplest solution would be setting a breakpoint just before/at the wanted line so you can see the variables just before the exception is called.

It's also possible to set an "exception breakpoint". This stops the script when a specific exception is encountered. Open "Run" > "View Breakpoints", click on the "+" sign and add a "Python Exception Breakpoint". Now you have to choose a specific exception.

Upvotes: 4

Related Questions