如何捕捉 PyQtGraph exceptions/errors?

How to catch PyQtGraph exceptions/errors?

通常,要捕获 Python 中的异常,您将使用带有特定错误的 try/except 处理程序,例如 AttributeErrorKeyError.

但是输出到控制台的 PyQtGraph 异常没有您可以捕获的特定处理程序。这是错误输出的示例

Traceback (most recent call last):

File "C:\Python27\lib\site-packages\pyqtgraph\graphicsItems\PlotCurveItem.py", line 353, in updateData

raise Exception("X and Y arrays must be the same shape--got %s and %s." % (self.xData.shape, self.yData.shape))

Exception: X and Y arrays must be the same shape--got (1L,) and (2001L,).

通常我会做一个 try/except 块,但有这样的特殊例外。

try:
    ...
except AttributeError:
    ...

我也不想在没有特定异常的情况下只使用 except。我知道异常是由于没有给 setData() 相同大小的 X 轴和 Y 轴 Numpy 数组引起的,但我想知道我一般如何能够捕获 PyQtGraph 异常。

我正在使用 PyQtGraph v0.10.0

查看可用的源代码here and at your error message, it appears that pyqtgraph is throwing Exceptions(注意 AttributeError 就在其中)

如果 pyqtgraph 也不是,你无法获得比这更具体的信息。

try:
    # ...
except Exception:
    # ...