Errors and warnings in Open Babel are handled internally by a flexible system motivated by a few factors:
Multiple error/warning levels exist and should be used by code. These are defined in the obMessageLevel enum as follows:
The default filter level is set to obWarning, which means that users are told of critical errors, but not non-standard formatting of input files. For more information, please see the API documentation for the OBMessageHandler class.
A global error handler obErrorLog (an instance of OBMessageHandler) is defined and can be used as illustrated below:
if (atomIndex < 1 || atomIndex > mol.NumAtoms() )
obErrorLog.ThrowError(__FUNCTION__, "Requested Atom Out of Range", obDebug);
stringstream errorMsg;
errorMsg << " Could not parse line in type translation table types.txt -- incorect number of columns";
errorMsg << " found " << vc.size() << " expected " << _ncols << ".";
obErrorLog.ThrowError(__FUNCTION__, errorMsg.str(), obInfo);
The __FUNCTION__ builtin is defined by many compilers (e.g., GCC) but can be defined to an empty string on some platforms without this compiler extension. It is currently used to provide information about which function is yielding the error or debugging information. This extension should eventually be replaced in the Open Babel code by __func__ which is now part of the C99 standard.