0

如何为 CreateFromDocument(input_xml) 捕获所有可能的 pyxb 异常。例子:

try:
    py_obj = CreateFromDocument(input_xml)
except pyxb.UnrecognizedContentError as e:
    raise e

这里它只捕获 UnrecognizedContentError。但是我想在使用 CreateFromDocument 时捕获所有可能的错误。我应该从 pyxb 使用什么正确的错误类?

谢谢你的帮助。

4

2 回答 2

1

PyXB 的异常层次结构在可能已过时的用户参考中进行了描述,并且API应该是其发布的最新版本。 pyxb.ValidationError最有可能捕获由 CreateFromDocument 引起的所有感兴趣的内容。 调试验证错误可能有助于从异常中恢复。

于 2014-01-11T02:40:20.107 回答
0

The only way to catch all possible exceptions is to catch the base Exception type - but that's not something you want to do. You just want to make sure you only catch the exceptions you can handle at this point in your code anyway... If you want to know which exceptions this call is most likely to raise, the doc and source code should tell you.

于 2013-12-31T14:24:07.300 回答