Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to debug on exceptions inside try except block?

Tags:

python

pycharm

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?

like image 935
algebruh Avatar asked Nov 02 '25 12:11

algebruh


1 Answers

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"

like image 168
Tomerikoo Avatar answered Nov 04 '25 01:11

Tomerikoo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!