msxml loadXML API error handling ambiguity

288 views Asked by At

I have a problem with understanding msxml API, particularly the 'IXMLDOMDocument::loadXML' function. According to the documentation, function returns HRESULT. When succeeded, it should return 'S_OK' which is a zero, also according to the documentation. But I've found different behaviour...

I got the code:

try {
  HRESULT res = xml->loadXML(xml_text);
  bool ret = SUCCEEDED(res);
}
catch (_com_error& ex) {
 //some error handling
}

If I load a valid xml file, then surprisingly 'res' is '-1' and the 'ret' becomes 'false'. It indicates that it failed to load that xml file. However, at the same time, there is no exception thrown... If I ignore returned value, and start processing the file, it turns out that xml file was loaded successfully...

It seems that exception handling is a proper way to verify if a file was loaded: no exception means loaded file. But I cannot understand, why the return values are messed up?

Finally, I cannot understand, why the exception handling is not mentioned in the documentation?

Can anybody explain to me that situation? Maybe I'm doing something wrong, but I don't know what...

0

There are 0 answers