Hi Jan, On Sat, Sep 15, 2012 at 12:47 AM, Jan Holst Jensen <j...@biochemfusion.com> wrote: > > I have now managed to produce a nice little self-contained DLL that uses > RDKit to do substructure mapping. It receives a query and a target molecule > as two MDL molfile strings. When the inputs are valid it behaves well and > returns the atom mapping to me. Yes :-).
Excellent! > However, when I give it an invalid MDL molfile as input, e.g. a text file > with regular prose, MolDataStreamToMol() throws a highly unexpected error > message. > > This piece of my test code: > > ifstream query_file ("C:\\SubstructData\\results.txt"); > > auto_ptr<RWMol> query (NULL); > unsigned int line = 0; > > try { > query.reset( MolDataStreamToMol(query_file, line, false, false, > false) ); > } catch (std::exception& e) { > cout << "STD-ERROR: " << e.what() << endl; > return 1; > } catch (...) { > cout << "UNK-ERROR: Unknown exception." << endl; > return 1; > } > > produces this output: > > [00:13:24] CTAB version string invalid at line 4 > STD-ERROR: Unknown exception > > In MolFileParser.cpp line 1881 I can locate the reported error message: > > std::ostringstream errout; > errout<<"CTAB version string invalid at line "<<line; > if(strictParsing){ > if(res) delete res; > throw FileParseException(errout.str()); > } else { > BOOST_LOG(rdWarningLog) << errout.str() << std::endl; > } > > Since I run with strictParsing==false the BOOST_LOG(rdWarningLog) call must > be the one that emits the first line of output, and I assume that the boost > warning log does not throw an exception. I haven't been able to figure out > where the exception gets thrown, but that must be later in the code. > > If I switch to strict parsing (last parameter in MolDataStreamToMol() set to > true) I don't see the boost log message anymore, only the single line > "STD-ERROR: Unknown exception". So strict parsing actually yields less error > message context. > > I hope the exception error message can be changed to something more > meaningful ? I would guess that the exception being thrown is a FileParseException. These don't do anything to override the what() method, so you get the "unknown exception" text. I will fix that. Here's the code from the python wrapper for constructing a molecule from a mol block ($RDBASE/Code/GraphMol/Wrap/rdmolfiles.cpp:MolFromMolFile()). It catches the exceptions that are likely to arise and returns a NULL if something fails. This might be useful: RWMol *newM=0; try { newM = MolFileToMol(molFilename, sanitize,removeHs,strictParsing); } catch (RDKit::BadFileException &e) { PyErr_SetString(PyExc_IOError,e.message()); throw python::error_already_set(); } catch (RDKit::FileParseException &e) { BOOST_LOG(rdWarningLog) << e.message() <<std::endl; } catch (...) { } return static_cast<ROMol *>(newM); -greg ------------------------------------------------------------------------------ How fast is your code? 3 out of 4 devs don\\\'t know how their code performs in production. Find out how slow your code is with AppDynamics Lite. http://ad.doubleclick.net/clk;262219672;13503038;z? http://info.appdynamics.com/FreeJavaPerformanceDownload.html _______________________________________________ Rdkit-discuss mailing list Rdkit-discuss@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/rdkit-discuss