简体   繁体   English

如何调试 try except 块内的异常?

[英]How to debug on exceptions inside try except block?

The PyCharm debugger has the feature to set breakpoints at raised exceptions. PyCharm 调试器具有在引发异常时设置断点的功能。 However if an exception is handled inside a try except block it is not raised.但是,如果在 try except 块内处理异常,则不会引发异常。 How to deal with this if I want to debug within the try block?如果我想在 try 块中进行调试,该如何处理? I could comment out the try except parts but this seems too cumbersome.我可以注释掉除了部分之外的尝试,但这似乎太麻烦了。 Is there a better solution?有更好的解决方案吗?

In the breakpoints settings (Either the在断点设置中(无论是断点符号 icon in the debug toolbar, or ctrl + shft + F8 ), you can set exception breakpoints .调试工具栏中的图标,或者ctrl + shft + F8 ),您可以设置异常断点

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" :要立即激活断点,即使处理了错误,也需要将激活策略设置为"On raise"

在设置中显示激活策略部分,设置为 On raise

Note: that warning sign which says: "This option may slow down the debugger"注意:那个警告标志说: “这个选项可能会减慢调试器的速度”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM