algebruh
algebruh

Reputation: 360

How to debug on exceptions inside try except block?

The PyCharm debugger has the feature to set breakpoints at raised exceptions. However if an exception is handled inside a try except block it is not raised. How to deal with this if I want to debug within the try block? I could comment out the try except parts but this seems too cumbersome. Is there a better solution?

Upvotes: 4

Views: 1002

Answers (1)

Tomerikoo
Tomerikoo

Reputation: 19432

In the breakpoints settings (Either the breakpoint symbol icon in the debug toolbar, or ctrl+shft+F8), you can set exception breakpoints.

The "Activation Policy" is usually set by default to "On termination". But since you handle the error, there is no termination. To activate the breakpoint immediately, even if the error is handled, you need to set the activation policy to "On raise":

showing the activation policy part in the settings, with On raise set

Note: that warning sign which says: "This option may slow down the debugger"

Upvotes: 3

Related Questions