I am using xml.dom.minidom for parsing some XML from a string. I need to handle an error case when the supplied XML is malformed. What error do I catch?
In other words, what should replace BadXml below?
try:
from xml.dom import minidom
in_xml = minidom.parseString(some_string)
except BadXml:
handle_bad_xml(some_string)
Ultimately the only answer is that you must catch
Exception.minidomdoes not implementDOMException, and while it does use some general exceptions fromxml.dom, it also freely usesTypeErrorand other standard python exceptions whose only single common base isExceptionitself.