What is the correct error class to be used to capture all exceptions for CreateFromDocument in pyxb

StackOverflow https://stackoverflow.com/questions/20857538

  •  23-09-2022
  •  | 
  •  

Question

How to capture all possible pyxb exceptions for CreateFromDocument(input_xml). Example:

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

Here it captures only UnrecognizedContentError. But I want to capture all possible errors when I use CreateFromDocument. What is the correct Error class should I use from pyxb?

Thanks for your help.

Was it helpful?

Solution 2

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.

OTHER TIPS

The exception hierarchy for PyXB is described in the user reference which may be out of date, and the API which should be current for its release. pyxb.ValidationError is most likely to catch everything of interest that arises from CreateFromDocument. Debugging Validation Errors may be helpful for recovery from exceptions.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top