コード例 #1
0
ファイル: type.cpp プロジェクト: Naoyuki-Yatsuda/griddb_nosql
Exception::NamedErrorCode Exception::tryCopyNamedErrorCode(
		const NamedErrorCode &src,
		DuplicatedLiteralFlags literalFlags) throw() {
	const SourceSymbolChar *name = tryCopyLiteral(
			src.getName(), FIELD_ERROR_CODE_NAME, literalFlags);

	return NamedErrorCode(src.getCode(), name);
}
コード例 #2
0
GSExceptionRegenerator::GSExceptionRegenerator(
	UTIL_EXCEPTION_CONSTRUCTOR_ARGS_LIST) throw()
	: fileNameLiteral_(fileNameLiteral),
	  functionNameLiteral_(functionNameLiteral),
	  critical_(false) {
	util::Exception cause;
	util::Exception::DuplicatedLiteralFlags filteredFlags;
	const util::Exception::DuplicatedLiteralFlags baseFlags =
		util::Exception::LITERAL_ALL_DUPLICATED;
	NamedErrorCode filteredCode;
	const char8_t *extraMessage = NULL;
	if (causeInHandling != NULL) {
		NamedErrorCode causeCode;
		bool userOrSystemThrown = false;
		bool unexpectedType = false;
		try {
			throw;
		}
		catch (const UserException &e) {
			cause = e;
			userOrSystemThrown = true;
			causeCode = selectErrorCode(e.getNamedErrorCode(),
				GS_EXCEPTION_NAMED_CODE(GS_ERROR_CM_INTERNAL_ERROR));
			filteredFlags = e.inheritLiteralFlags(baseFlags) | literalFlags;
		}
		catch (const SystemException &e) {
			cause = e;
			critical_ = true;
			userOrSystemThrown = true;
			causeCode = selectErrorCode(e.getNamedErrorCode(),
				GS_EXCEPTION_NAMED_CODE(GS_ERROR_CM_INTERNAL_ERROR));
			filteredFlags = e.inheritLiteralFlags(baseFlags) | literalFlags;
		}
		catch (const util::PlatformException &e) {
			cause = e;
			causeCode = GS_EXCEPTION_NAMED_CODE(GS_ERROR_CM_PLATFORM_ERROR);
			filteredFlags = e.inheritLiteralFlags(baseFlags) | literalFlags;
		}
		catch (const util::UtilityException &e) {
			cause = e;
			switch (e.getErrorCode()) {
			case util::UtilityException::CODE_NO_MEMORY:
				causeCode = GS_EXCEPTION_NAMED_CODE(GS_ERROR_CM_NO_MEMORY);
				break;
			case util::UtilityException::CODE_MEMORY_LIMIT_EXCEEDED:
				causeCode =
					GS_EXCEPTION_NAMED_CODE(GS_ERROR_CM_MEMORY_LIMIT_EXCEEDED);
				break;
			case util::UtilityException::CODE_SIZE_LIMIT_EXCEEDED:
				causeCode =
					GS_EXCEPTION_NAMED_CODE(GS_ERROR_CM_SIZE_LIMIT_EXCEEDED);
				break;
			default:
				causeCode = GS_EXCEPTION_NAMED_CODE(GS_ERROR_CM_INTERNAL_ERROR);
				extraMessage = "Internal error by unexpected utility problem";
				break;
			}
			filteredFlags = literalFlags;
		}
		catch (const util::Exception &e) {
			cause = e;
			if (e.getErrorCode() == 0) {
				critical_ = true;
				unexpectedType = true;
				causeCode = GS_EXCEPTION_NAMED_CODE(GS_ERROR_CM_INTERNAL_ERROR);
				filteredFlags = literalFlags;
			}
			else {
				causeCode = e.getNamedErrorCode();
				filteredFlags = e.inheritLiteralFlags(baseFlags) | literalFlags;
			}
		}
		catch (const std::bad_alloc &) {
			causeCode = GS_EXCEPTION_NAMED_CODE(GS_ERROR_CM_NO_MEMORY);
			filteredFlags = literalFlags;
		}
		catch (...) {
			critical_ = true;
			unexpectedType = true;
			causeCode = GS_EXCEPTION_NAMED_CODE(GS_ERROR_CM_INTERNAL_ERROR);
			filteredFlags = literalFlags;
		}
		filteredCode = selectErrorCode(namedErrorCode, causeCode);

		if (userOrSystemThrown &&
			causeCode.getCode() == GS_ERROR_CM_INTERNAL_ERROR &&
			cause.getErrorCode() == GS_ERROR_DEFAULT) {
			extraMessage = "Internal error by empty error code";
		}
		else if (unexpectedType) {
			extraMessage = "Internal error by unexpected exception type";
		}
	}
	else {
		filteredCode = namedErrorCode;
		filteredFlags = literalFlags;
	}
	filteredCode = selectErrorCode(
		filteredCode, GS_EXCEPTION_NAMED_CODE(GS_ERROR_CM_INTERNAL_ERROR));

	typedef util::NormalOStringStream StrStream;
	typedef util::Exception::NoThrowString<StrStream::allocator_type> SafeStr;

	StrStream baseStream;
	baseStream << cause.getField(util::Exception::FIELD_MESSAGE);
	SafeStr baseStr(baseStream);
	const char8_t *strPtr = baseStr.get();
	const char8_t *baseMessage =
		(message != NULL && strlen(message) > 0)
			? message
			: (strPtr == NULL || strlen(strPtr) > 0 ? strPtr : NULL);

	StrStream messageStream;
	if (extraMessage == NULL) {
		if (baseMessage != NULL) {
			messageStream << baseMessage;
		}
	}
	else {
		messageStream << extraMessage;
		if (baseMessage != NULL) {
			messageStream << " (reason=" << baseMessage << ")";
		}
	}

	base_ = util::Exception(filteredCode, SafeStr(messageStream).get(), NULL,
		NULL, lineNumber, causeInHandling, typeNameLiteral, stackTraceMode,
		filteredFlags);
}