当前位置: 首页>>代码示例>>C++>>正文


C++ Exception::set方法代码示例

本文整理汇总了C++中Exception::set方法的典型用法代码示例。如果您正苦于以下问题:C++ Exception::set方法的具体用法?C++ Exception::set怎么用?C++ Exception::set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Exception的用法示例。


在下文中一共展示了Exception::set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: setIntern

bool SocketAddress::setIntern(Exception& ex,const string& hostAndPort,bool resolveHost) {
	ASSERT_RETURN(!hostAndPort.empty(),false);

	string host, port;
	auto it  = hostAndPort.begin();
	auto& end = hostAndPort.end();
	if (*it == '[') {
		++it;
		while (it != end && *it != ']')
			host += *it++;
		if (it == end) {
			ex.set(Exception::NETADDRESS,"Malformed IPv6 address ", hostAndPort);
			return false;
		}
		++it;
	} else {
		while (it != end && *it != ':')
			host += *it++;
	}
	if (it != end && *it == ':') {
		++it;
		while (it != end)
			port += *it++;
	}
	else {
		ex.set(Exception::NETADDRESS, "Missing port number in ", hostAndPort);
		return false;
	}
	return setIntern(ex,host, resolveService(ex,port),resolveHost);
}
开发者ID:jaejungkim,项目名称:MonaServer,代码行数:30,代码来源:SocketAddress.cpp

示例2: Remove

bool FileSystem::Remove(Exception& ex,const char* path,bool all) {
	bool isFolder(IsFolder(path));
	if (all && isFolder) {
		FileSystem::ForEach forEach([&ex](const string& filePath){
			Remove(ex, filePath, true);
		});
		Exception ignore;
		Paths(ignore, path, forEach); // if exception it's a not existent folder
	}
	if (!Exists(path))
		return !ex;; // already removed!
#if defined(_WIN32)
	if (isFolder) {
		wchar_t wFile[_MAX_PATH];
		MultiByteToWideChar(CP_UTF8, 0, path, -1, wFile, _MAX_PATH);
		if (RemoveDirectoryW(wFile)==0)
			ex.set(Exception::FILE, "Impossible to remove folder ", path);
	} else {
		wchar_t wFile[_MAX_PATH];
		MultiByteToWideChar(CP_UTF8, 0, path, -1, wFile, _MAX_PATH);
		if(_wremove(wFile) != 0)
			ex.set(Exception::FILE, "Impossible to remove file ", path);
	}
	return !ex;
#endif
	if (remove(path) == 0)
		return !ex;
	if (isFolder)
		ex.set(Exception::FILE, "Impossible to remove folder ", path);
	else
		ex.set(Exception::FILE, "Impossible to remove file ", path);
	return false;
}
开发者ID:keyanmca,项目名称:MonaServer,代码行数:33,代码来源:FileSystem.cpp

示例3: Paths

UInt32 FileSystem::Paths(Exception& ex, const char* path, const ForEach& forEach) {
	int err = 0;
	string directory(path);
	FileSystem::MakeDirectory(directory);
	UInt32 count(0);
	string pathFile;

#if defined(_WIN32)
	directory.append("*");

	wchar_t wDirectory[_MAX_PATH];
	MultiByteToWideChar(CP_UTF8, 0, directory.c_str(), -1, wDirectory, _MAX_PATH);
	
	WIN32_FIND_DATAW fileData;
	HANDLE	fileHandle = FindFirstFileW(wDirectory, &fileData);
	if (fileHandle == INVALID_HANDLE_VALUE) {
		if ((err = GetLastError()) != ERROR_NO_MORE_FILES) {
			ex.set(Exception::FILE, "The system cannot find the directory ", path);
			return count;
		}
		return count;
	}
	do {
		if (wcscmp(fileData.cFileName, L".") != 0 && wcscmp(fileData.cFileName, L"..") != 0) {
			++count;
			String::Append(MakeDirectory(pathFile.assign(path)), fileData.cFileName);
			if (fileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
				pathFile.append("/");
			forEach(pathFile);
		}
	} while (FindNextFileW(fileHandle, &fileData) != 0);
	FindClose(fileHandle);
#else
	DIR* pDirectory = opendir(directory.c_str());
	if (!pDirectory) {
		ex.set(Exception::FILE, "The system cannot find the directory ",directory);
		return count;
	}
	struct dirent* pEntry(NULL);
	while((pEntry = readdir(pDirectory))) {
		if (strcmp(pEntry->d_name, ".")!=0 && strcmp(pEntry->d_name, "..")!=0) {
			++count;
			String::Append(pathFile.assign(directory), pEntry->d_name);
			// Cross-platform solution when DT_UNKNOWN or symbolic link
			if(pEntry->d_type==DT_DIR)
				pathFile.append("/");
			else if(pEntry->d_type==DT_UNKNOWN || pEntry->d_type==DT_LNK) {
				Status status;
				Stat(pathFile, status);
				if ((status.st_mode&S_IFMT) == S_IFDIR)
					pathFile.append("/");
			}
			forEach(pathFile);
		}
	}
	closedir(pDirectory);
#endif
	return count;
}
开发者ID:keyanmca,项目名称:MonaServer,代码行数:59,代码来源:FileSystem.cpp

示例4: LUAToXML

bool LUAXML::LUAToXML(Exception& ex, lua_State* pState, int index, const PoolBuffers& poolBuffers) {
	// index - LUA XML table
	if (!lua_istable(pState, index)) {
		ex.set(Exception::APPLICATION, "Just LUA table can be convert to XML");
		return false;
	}

	PacketWriter writer(poolBuffers);
	const char* name(NULL);
	bool result(false);
	
	lua_pushnil(pState);  // first key 
	while (lua_next(pState, index) != 0) {
		// uses 'key' (at index -2) and 'value' (at index -1) 
		if (lua_type(pState, -2) == LUA_TSTRING) {

			name = lua_tostring(pState, -2);

			if (lua_istable(pState, -1)) {

				// information fields { xml = {version = 1.0}, ... }

				writer.write("<?").write(name).write(" ");

				lua_pushnil(pState);  // first key 
				while (lua_next(pState, -2) != 0) {
					// uses 'key' (at index -2) and 'value' (at index -1) 
					if (lua_type(pState, -2) == LUA_TSTRING && lua_isstring(pState, -1))
						writer.write(lua_tostring(pState, -2)).write("=\"").write(lua_tostring(pState, -1)).write("\" ");
					else
						ex.set(Exception::APPLICATION, "Bad ", name, " XML attribute information, key must be string and value convertible to string");
					lua_pop(pState, 1);
				}

				writer.write("?>");
			} else
				ex.set(Exception::APPLICATION, "Bad ",name," XML information, value must be a table");

		} else if (lua_isnumber(pState, -2)) {
			if(lua_istable(pState, -1))
				result = LUAToXMLElement(ex, pState, writer);
			else
				ex.set(Exception::APPLICATION, "Impossible to write inner XML data on the top of XML level");
		}  else
			ex.set(Exception::APPLICATION, "Impossible to convert the key of type ",lua_typename(pState,lua_type(pState,-2)),"to a correct XML root element");

		lua_pop(pState, 1);
	}

	if (result)
		lua_pushlstring(pState,STR writer.data(), writer.size());

	return result;
}
开发者ID:8088,项目名称:MonaServer,代码行数:54,代码来源:LUAXML.cpp

示例5: run

bool SocketSender::run(Exception& ex) {
	if (!_pSocket) {
		ex.set(Exception::SOCKET, "SocketSender ", name, " started in parallel without pointer of socket");
		return false;
	}
	// send
	Exception exc;
	shared_ptr<SocketSender> pThis(_pThis);
	_pSocket->send(exc, pThis);
	if (exc.code() != Exception::ASSERT)
		ex.set(exc);
	return true;
}
开发者ID:TeddySong,项目名称:MonaServer,代码行数:13,代码来源:SocketSender.cpp

示例6: GetSize

UInt32 FileSystem::GetSize(Exception& ex,const char* path) {
	Status status;
	status.st_size = 0;
	string file(path);
	size_t oldSize(file.size());
	if (Stat(MakeFile(file).c_str(), status) != 0 || status.st_mode&S_IFDIR) {
		ex.set(Exception::FILE, "File ", path, " doesn't exist");
		return 0;
	}
	if (oldSize>file.size()) { // if was a folder
		ex.set(Exception::FILE, "GetSize works just on file, and ", path, " is a folder");
		return 0;
	}
	return (UInt32)status.st_size;
}
开发者ID:keyanmca,项目名称:MonaServer,代码行数:15,代码来源:FileSystem.cpp

示例7: type

WinRegistryKey::Type WinRegistryKey::type(Exception& ex,const string& name) {
	if (!open(ex))
		return REGT_NONE;
	DWORD type = REG_NONE;
	DWORD size;
	if (RegQueryValueExA(_hKey, name.c_str(), NULL, &type, NULL, &size) != ERROR_SUCCESS) {
		ex.set(Exception::REGISTRY, "Key ", key(name), " not found");
		return REGT_NONE;
	}
	if (type != REG_SZ && type != REG_EXPAND_SZ && type != REG_DWORD) {
		ex.set(Exception::REGISTRY, key(name), ", type not supported");
		return REGT_NONE;
	}
	return (Type)type;
}
开发者ID:8088,项目名称:MonaServer,代码行数:15,代码来源:WinRegistryKey.cpp

示例8: run

bool RTMFPCookieComputing::run(Exception& ex) {
	// First execution is for the DH computing if pDH == null, else it's to compute Diffie-Hellman keys
	if (!_diffieHellman.initialized())
		return _diffieHellman.initialize(ex);

	// Compute Diffie-Hellman secret
	_diffieHellman.computeSecret(ex,initiatorKey.data(),initiatorKey.size(),_sharedSecret);
	if (ex)
		return false;

	if (packet.size() > 0) {
		ex.set(Exception::CRYPTO, "RTMFPCookieComputing already executed");
		return false;
	}

	// string hex;
	// DEBUG("Shared Secret : ", Util::FormatHex(_sharedSecret.data(), _sharedSecret.size(), hex));

	// It's our key public part
	int size = _diffieHellman.publicKeySize(ex);
	if (size<0) {
		if (!ex)
			ex.set(Exception::CRYPTO, "DH public key not initialized");
		return false;
	}
	packet.write7BitLongValue(size+11);
	UInt32 noncePos = packet.size();
	packet.writeRaw(EXPAND_DATA_SIZE("\x03\x1A\x00\x00\x02\x1E\x00"));
	UInt8 byte2 = DH_KEY_SIZE-size;
	if(byte2>2) {
		CRITIC("Generation DH key with less of 126 bytes!");
		byte2=2;
	}
	packet.write8(0x81);
	packet.write8(2-byte2);
	packet.write8(0x0D);
	packet.write8(0x02);
	if (size>2000)
		ERROR("RTMFP diffie hellman public key with an error size key of ",size) // TODO remove this log one time fixed!
	_diffieHellman.readPublicKey(ex,packet.buffer(size));
	packet.write8(0x58);

	// Compute Keys
	RTMFP::ComputeAsymetricKeys(_sharedSecret,initiatorNonce.data(),initiatorNonce.size(),packet.data()+noncePos,size+11,decryptKey,encryptKey);
	
	waitHandle();
	return true;
}
开发者ID:taililong,项目名称:MonaServer,代码行数:48,代码来源:RTMFPCookieComputing.cpp

示例9: run

bool HTTPSender::run(Exception& ex) {
	if (!_pRequest && (!_pWriter || _sizePos>0)) { // accept just HTTPSender::writeRaw call, for media streaming
		ex.set(Exception::PROTOCOL, "No HTTP request to send the reply");
		return false;
	}

	if (!_pWriter) {

		//// GET FILE
		Time time;
		// Not Modified => don't send the file
		if (_file.lastModified()>0 && _pRequest->ifModifiedSince >= _file.lastModified()) {
			write("304 Not Modified", HTTP::CONTENT_ABSENT);
		} else {
			if (_file.lastModified()==0) {
				// file doesn't exist, test directory
				string dir(_file.fullPath());
				if (FileSystem::Exists(FileSystem::MakeDirectory(dir))) {
					// Redirect to the real path of directory
					DataWriter& response = write("301 Moved Permanently"); // TODO check that it happens sometimes or never!
					BinaryWriter& writer = response.packet;
					String::Format(_buffer, "http://", _pRequest->serverAddress, _file.path(), '/');
					HTTP_BEGIN_HEADER(writer)
						HTTP_ADD_HEADER(writer, "Location", _buffer)
					HTTP_END_HEADER(writer)
					HTML_BEGIN_COMMON_RESPONSE(writer, "Moved Permanently")
						writer.writeRaw("The document has moved <a href=\"", _buffer, "\">here</a>.");
					HTML_END_COMMON_RESPONSE(writer, _buffer)
				} else
					writeError(404, String::Format(_buffer,"File ", _file.path(), " doesn't exist"));
			} else {
开发者ID:jaejungkim,项目名称:MonaServer,代码行数:31,代码来源:HTTPSender.cpp

示例10: onConnection

void Peer::onConnection(Exception& ex, Writer& writer,DataReader& parameters,DataWriter& response) {
	if(!connected) {
		_pWriter = &writer;

		// reset default protocol parameters
		_parameters.clear();
		Parameters::ForEach forEach([this](const string& key,const string& value) {
			_parameters.setString(key,value);
		});
		string buffer;
		_handler.iterate(String::Format(buffer,protocol,"."), forEach);

		ParameterWriter parameterWriter(_parameters);
		SplitWriter parameterAndResponse(parameterWriter,response);

		_handler.onConnection(ex, *this,parameters,parameterAndResponse);
		if (!ex) {
			(bool&)connected = ((Entities<Client>&)_handler.clients).add(*this);
			if (!connected) {
				ex.set(Exception::PROTOCOL, "Client ", Util::FormatHex(id, ID_SIZE, buffer), " exists already");
				ERROR(ex.error());
				_handler.onDisconnection(*this);
			}
		}
		if (!connected) {
			writer.abort();
			_pWriter = NULL;
		} else {
			OnInitParameters::raise(_parameters);
			DEBUG("Client ",address.toString()," connection")
		}
		writer.open(); // open even if "ex" to send error messages!
	} else
开发者ID:fxlt,项目名称:MonaServer,代码行数:33,代码来源:Peer.cpp

示例11: Read

bool LUAIPAddress::Read(Exception& ex, lua_State *pState, int index, IPAddress& address,bool withDNS) {

	if (lua_type(pState, index)==LUA_TSTRING) // lua_type because can be encapsulated in a lua_next
		return withDNS ? address.setWithDNS(ex, lua_tostring(pState,index)) : address.set(ex, lua_tostring(pState,index));

	if(lua_istable(pState,index)) {
		bool isConst;

		IPAddress* pOther = Script::ToObject<IPAddress>(pState, isConst, index);
		if (pOther) {
			address.set(*pOther);
			return true;
		}

		SocketAddress* pAddress = Script::ToObject<SocketAddress>(pState, isConst, index);
		if (pAddress) {
			address.set(pAddress->host());
			return true;
		}

		ServerConnection* pServer = Script::ToObject<ServerConnection>(pState, isConst, index);
		if (pServer) {
			address.set(pServer->address.host());
			return true;
		}
	}

	ex.set(Exception::NETADDRESS, "No valid IPAddress available to read");
	return false;
}
开发者ID:blueram,项目名称:MonaServer,代码行数:30,代码来源:LUAIPAddress.cpp

示例12:

ADD_TEST(DateTest, ParseISO8601Frac) {
	
	CHECK(Parse("2005-01-08T12:30:00.1Z", 2005, 1, 8,6, 12, 30, 0, 100, Date::GMT));
	CHECK(_Date.toString(Date::ISO8601_FRAC_FORMAT, _Out) == "2005-01-08T12:30:00.100Z");
	
	CHECK(Parse("2005-01-08T12:30:00.123+01:00", 2005, 1, 8,6, 12, 30, 0, 123, 3600000));
	CHECK(_Date.toString(Date::ISO8601_FRAC_FORMAT, _Out) == "2005-01-08T12:30:00.123+01:00");
	
	CHECK(Parse("2005-01-08T12:30:00Z", 2005, 1, 8,6, 12, 30, 0, 0, Date::GMT));
	CHECK(_Date.toString(Date::ISO8601_FRAC_FORMAT, _Out) == "2005-01-08T12:30:00.000Z");
	
	CHECK(Parse("2005-01-08T12:30:00+01:00", 2005, 1, 8,6, 12, 30, 0, 0, 3600000));
	CHECK(_Date.toString(Date::ISO8601_FRAC_FORMAT, _Out) == "2005-01-08T12:30:00.000+01:00");

	CHECK(Parse("2014-04-22T06:00:00.000+02:00", 2014, 4, 22, 2, 6, 0, 0, 0, 7200000));
	CHECK(_Date.toString(Date::ISO8601_FRAC_FORMAT, _Out) == "2014-04-22T06:00:00.000+02:00");

	CHECK(!Ex);

	CHECK(Parse("2005-01-08T12:30:00.12345-01:00", 2005, 1, 8,6, 12, 30, 0, 123, -3600000));
	CHECK(_Date.toString(Date::ISO8601_FRAC_FORMAT, _Out) == "2005-01-08T12:30:00.123-01:00");
	
	CHECK(Parse("2010-09-23T16:17:01.2817002+02:00", 2010, 9, 23, 4, 16, 17, 1, 281, 7200000));
	CHECK(_Date.toString(Date::ISO8601_FRAC_FORMAT, _Out) == "2010-09-23T16:17:01.281+02:00");
	
	CHECK(Parse("2005-01-08T12:30:00.123456", 2005, 1, 8,6, 12, 30, 0, 123, Date::LOCAL));

	CHECK(Parse("2005-01-08T12:30:00.012034", 2005, 1, 8,6, 12, 30, 0, 12, Date::LOCAL));
	_Date.setOffset(4020000);
	CHECK(_Date.offset()==4020000);
	CHECK(_Date.toString(Date::ISO8601_FRAC_FORMAT, _Out) == "2005-01-08T12:30:00.012+01:07");

	CHECK(Ex); // warning on microsecond lost information
	Ex.set(Exception::NIL);
}
开发者ID:TeddySong,项目名称:MonaServer,代码行数:35,代码来源:DateTest.cpp

示例13: LUAToXMLElement

bool LUAXML::LUAToXMLElement(Exception& ex, lua_State* pState, PacketWriter& writer) {
	// -1 => table

	lua_pushstring(pState, "__name");
	lua_rawget(pState, -2);
	const char* name(lua_tostring(pState, -1));
	lua_pop(pState, 1);
	if (!name) {
		ex.set(Exception::APPLICATION, "Impossible to write a XML element without name (__name)");
		return false;
	}

	// write attributes
	writer.write("<").write(name).write(" ");
	lua_pushnil(pState);  // first key 
	while (lua_next(pState, -2) != 0) {
		// uses 'key' (at index -2) and 'value' (at index -1) 
		if (lua_type(pState, -2) == LUA_TSTRING && strcmp(lua_tostring(pState, -2),"__name")!=0 && lua_isstring(pState, -1))
			writer.write(lua_tostring(pState, -2)).write("=\"").write(lua_tostring(pState, -1)).write("\" ");
		lua_pop(pState, 1);
	}
	if (lua_objlen(pState, -1) == 0) {
		writer.write("/>");
		return true;
	}

	writer.write(">");

	// write elements
	lua_pushnil(pState);  // first key 
	while (lua_next(pState, -2) != 0) {
		// uses 'key' (at index -2) and 'value' (at index -1) 
		if (lua_isnumber(pState, -2)) {
			if (lua_istable(pState, -1))
				LUAToXMLElement(ex, pState, writer); // table child
			else if (lua_isstring(pState, -1))
				writer.write(lua_tostring(pState, -1), lua_objlen(pState, -1)); // __value
			else
				ex.set(Exception::APPLICATION, "Impossible to convert the value of type ", lua_typename(pState, lua_type(pState, -1)), "to a correct XML value of ",name);
		} else if (lua_type(pState, -2) != LUA_TSTRING)
			ex.set(Exception::APPLICATION, "Impossible to convert the key of type ",lua_typename(pState,lua_type(pState,-2)),"to a correct XML element of ",name);
		lua_pop(pState, 1);
	}

	writer.write("</").write(name).write(">");
	return true;
}
开发者ID:8088,项目名称:MonaServer,代码行数:47,代码来源:LUAXML.cpp

示例14: Decode

bool RTMFP::Decode(Exception& ex,RTMFPEngine& aesDecrypt,PacketReader& packet) {
	// Decrypt
	aesDecrypt.process(packet.current(),(UInt8*)packet.current(),packet.available());
	bool result = ReadCRC(packet);
	if (!result)
		ex.set(Exception::CRYPTO, "Bad RTMFP CRC sum computing");
	return result;
}
开发者ID:luc1el,项目名称:MonaServer,代码行数:8,代码来源:RTMFP.cpp

示例15: setString

bool WinRegistryKey::setString(Exception& ex, const string& name, const string& value) {
	if (!open(ex))
		return false;
	if (RegSetValueExA(_hKey, name.c_str(), 0, REG_SZ, (CONST BYTE*) value.c_str(), (DWORD) value.size() + 1) == ERROR_SUCCESS)
		return true;
	ex.set(Exception::REGISTRY, "Failed to set registry value ", key(name));
	return false;
}
开发者ID:8088,项目名称:MonaServer,代码行数:8,代码来源:WinRegistryKey.cpp


注:本文中的Exception::set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。