Hi,
In my app i am using loadUrl to load in an xml file from a dropbox folder. When the file in dropbox is deleted my app crashes.
ci::DataSourceRef dataSourceRef = ci::loadUrl(strFullPath.c_str());
assert(dataSourceRef);
if (!dataSourceRef) return;
if (!dataSourceRef->getBuffer()) return;
if (dataSourceRef->getBuffer()->getSize() == 0) return;
doc = ci::XmlTree(dataSourceRef);
It seems to load something in (not sure what! i have deleted the file in dropbox!!) and try to parse it, causing a crash in doc.parserapidxml::parse_doctype_node( bufString.get() );
void XmlTree::loadFromDataSource( DataSourceRef dataSource, XmlTree *result, const XmlTree::ParseOptions &parseOptions )
{
auto buf = dataSource->getBuffer();
size_t dataSize = buf->getSize();
unique_ptr<char[]> bufString( new char[dataSize+1] );
memcpy( bufString.get(), buf->getData(), buf->getSize() );
bufString.get()[dataSize] = 0;
rapidxml::xml_document<> doc; // character type defaults to char
if( parseOptions.getParseComments() )
doc.parse<rapidxml::parse_comment_nodes | rapidxml::parse_doctype_node>( bufString.get() );
else
**doc.parse<rapidxml::parse_doctype_node>( bufString.get() );**
parseItem( doc, NULL, result, parseOptions );**
result->setNodeType( NODE_DOCUMENT ); // call this after parse - constructor replaces it
}
If the xml file is deleted i would like my app to handle this gracefully instead of crashing as it does now.
Is there a way for loadUrl to detect the file no longer exists and to throw its exception or tell me before it crashes?