小编Fuz*_*ury的帖子

Pycharm - 中断任何异常但忽略 StopIteration 和 ExitGenerator

在 Pycharm 中,我想在调试模式下,停止进入我的代码的任何异常,但忽略由库函数抛出和捕获的任何异常。

Pycharm 在断点中有一个名为 Any Exception 的选项,您可以在其中说“On Raise”和“Ignore library files”,这有很长的路要走,但它不会忽略 StopIteration 和 ExitGenerator,这意味着它会在任何生成器或产量声明。

例如,在下面的代码中,生成器next((x for x in a_list))抛出一个 ExitGenerator 异常,Pycharm 在调试模式下停止该异常,但这实际上是由库代码捕获和处理的,所以我想忽略它。

参见例如这个程序

import pandas as pd

try:
    # spurious exception
    a_list = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h']
    first_item = next((x for x in a_list))
    print(f'first item = {first_item}')

except Exception as e:
    # the program won't go here as the ExitGenerator exception is handled by the standard library
    print(f'got exception from generator : {str(e)}') …
Run Code Online (Sandbox Code Playgroud)

python debugging exception pycharm

2
推荐指数
1
解决办法
202
查看次数

标签 统计

debugging ×1

exception ×1

pycharm ×1

python ×1