static string showErrorContext(const XmlException &e, const char *query)
{
	ostringstream msg;
	msg << e.what();
	if(e.getQueryLine() != 0 && e.getQueryFile() == 0) {
		msg << endl;
		int line = 1;
		while(line != e.getQueryLine() && *query != 0) {
			if(*query == '\n' ||
				(*query == '\r' && *(query + 1) != '\n'))
				++line;
			++query;
		}
		if(line == e.getQueryLine()) {
			while(*query != 0) {
				msg << (*query);
				if(*query == '\n' ||
					(*query == '\r' && *(query + 1) != '\n'))
					break;
				++query;
			}
			if(e.getQueryColumn() != 0) {
				if(*query == 0) msg << endl;
				msg << string(e.getQueryColumn() - 1, ' ') << "^";
			}
		}
	}
	return msg.str();
}
Exemple #2
0
void RepNode::throwIfUnExpected(XmlException &xe)
{
	if (xe.getExceptionCode() != XmlException::DATABASE_ERROR ||
	    (xe.getDbErrno() != DB_LOCK_DEADLOCK &&
	     xe.getDbErrno() != DB_REP_HANDLE_DEAD &&
	     xe.getDbErrno() != DB_REP_LOCKOUT)) {

		ostringstream o;
		o << envHome_ << ":" << xe.what() << endl;
		if (xe.getExceptionCode() == XmlException::DATABASE_ERROR)
			o << "DB_ERRNO:" << xe.getDbErrno() << endl;

		printMsg(o);
		throw xe;
	}
}