mirror of
				https://github.com/vcmi/vcmi.git
				synced 2025-10-31 00:07:39 +02:00 
			
		
		
		
	Throwing runtime_errors instead of string (or even char*) objects.
This commit is contained in:
		| @@ -1853,7 +1853,7 @@ void CAdvMapInt::tileLClicked(const int3 &mp) | ||||
| 	} //end of hero is selected "case" | ||||
| 	else | ||||
| 	{ | ||||
| 		throw std::string("Nothing is selected..."); | ||||
| 		throw std::runtime_error("Nothing is selected..."); | ||||
| 	} | ||||
|  | ||||
| 	if(const IShipyard *shipyard = ourInaccessibleShipyard(topBlocking)) | ||||
|   | ||||
| @@ -343,7 +343,7 @@ SDL_Surface * CDefHandler::getSprite (int SIndex, const ui8 * FDef, const BMPPal | ||||
| 	break; | ||||
|  | ||||
| 	default: | ||||
| 		throw std::string("Unknown sprite format."); | ||||
| 		throw std::runtime_error("Unknown sprite format."); | ||||
| 		break; | ||||
| 	} | ||||
|  | ||||
| @@ -365,7 +365,7 @@ CDefHandler * CDefHandler::giveDef(const std::string & defName) | ||||
| { | ||||
| 	ui8 * data = spriteh->giveFile(defName, FILE_ANIMATION); | ||||
| 	if(!data) | ||||
| 		throw "bad def name!"; | ||||
| 		throw std::runtime_error("bad def name!"); | ||||
| 	CDefHandler * nh = new CDefHandler(); | ||||
| 	nh->openFromMemory(data, defName); | ||||
| 	delete [] data; | ||||
|   | ||||
| @@ -614,7 +614,7 @@ static void setScreenRes(int w, int h, int bpp, bool fullscreen, bool resetVideo | ||||
| 	if((screen = SDL_SetVideoMode(w, h, suggestedBpp, SDL_SWSURFACE|(fullscreen?SDL_FULLSCREEN:0))) == NULL) | ||||
| 	{ | ||||
| 		tlog1 << "Requested screen resolution is not available (" << w << "x" << h << "x" << suggestedBpp << "bpp)\n"; | ||||
| 		throw "Requested screen resolution is not available\n"; | ||||
| 		throw std::runtime_error("Requested screen resolution is not available\n"); | ||||
| 	} | ||||
|  | ||||
| 	tlog0 << "New screen flags: " << screen->flags << std::endl; | ||||
|   | ||||
| @@ -262,7 +262,7 @@ void CClient::loadGame( const std::string & fname ) | ||||
| 	*serv << fname; | ||||
| 	*serv >> pom8; | ||||
| 	if(pom8)  | ||||
| 		throw "Server cannot open the savegame!"; | ||||
| 		throw std::runtime_error("Server cannot open the savegame!"); | ||||
| 	else | ||||
| 		tlog0 << "Server opened savegame properly.\n"; | ||||
|  | ||||
| @@ -325,7 +325,7 @@ void CClient::newGame( CConnection *con, StartInfo *si ) | ||||
| 		c << *si; | ||||
| 		c >> pom8; | ||||
| 		if(pom8)  | ||||
| 			throw "Server cannot open the map!"; | ||||
| 			throw std::runtime_error("Server cannot open the map!"); | ||||
| 		else | ||||
| 			tlog0 << "Server opened map properly.\n"; | ||||
| 	} | ||||
|   | ||||
| @@ -418,7 +418,7 @@ SDLKey CGuiHandler::arrowToNum( SDLKey key ) | ||||
| 	default: | ||||
| 		assert(0); | ||||
| 	} | ||||
| 	throw std::string("Wrong key!"); | ||||
| 	throw std::runtime_error("Wrong key!"); | ||||
| } | ||||
|  | ||||
| SDLKey CGuiHandler::numToDigit( SDLKey key ) | ||||
|   | ||||
| @@ -1259,7 +1259,7 @@ void CSDL_Ext::applyEffect( SDL_Surface * surf, const SDL_Rect * rect, int mode | ||||
| 		} | ||||
| 		break; | ||||
| 	default: | ||||
| 		throw std::string("Unsuppoerted efftct!"); | ||||
| 		throw std::runtime_error("Unsuppoerted efftct!"); | ||||
| 	} | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -83,7 +83,7 @@ std::string makeNumberShort(IntType number) //the output is a string containing | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	throw std::string("We shouldn't be here - makeNumberShort"); | ||||
| 	throw std::runtime_error("We shouldn't be here - makeNumberShort"); | ||||
| } | ||||
|  | ||||
| typedef void (*TColorPutter)(Uint8 *&ptr, const Uint8 & R, const Uint8 & G, const Uint8 & B); | ||||
|   | ||||
| @@ -27,7 +27,7 @@ void BattleHex::operator+=(EDir dir) | ||||
| 		setXY(x-1, y); | ||||
| 		break; | ||||
| 	default: | ||||
| 		throw std::string("Disaster: wrong direction in BattleHex::operator+=!\n"); | ||||
| 		throw std::runtime_error("Disaster: wrong direction in BattleHex::operator+=!\n"); | ||||
| 		break; | ||||
| 	} | ||||
| } | ||||
|   | ||||
| @@ -26,7 +26,7 @@ static ui32 readNr(std::string &in, int &it) | ||||
| 		if(in[last]=='\t' || in[last]=='\n' || in[last]==' ' || in[last]=='\r' || in[last]=='\n') | ||||
| 			break; | ||||
| 	if(last==in.size()) | ||||
| 		throw std::string("Cannot read number..."); | ||||
| 		throw std::runtime_error("Cannot read number..."); | ||||
|  | ||||
| 	std::istringstream ss(in.substr(it,last-it)); | ||||
| 	it+=(1+last-it); | ||||
|   | ||||
| @@ -356,7 +356,7 @@ bool CCampaignHandler::startsAt( const ui8 * buffer, int size, int pos ) | ||||
| 			if(place < size) | ||||
| 				return buffer[place]; | ||||
|  | ||||
| 			throw std::string("Out of bounds!"); | ||||
| 			throw std::runtime_error("Out of bounds!"); | ||||
| 		} | ||||
| 	}; | ||||
| 	try | ||||
|   | ||||
| @@ -15,7 +15,7 @@ const CStackInstance &CCreatureSet::operator[](TSlot slot) const | ||||
| 	if (i != stacks.end()) | ||||
| 		return *i->second; | ||||
| 	else | ||||
| 		throw std::string("That slot is empty!"); | ||||
| 		throw std::runtime_error("That slot is empty!"); | ||||
| } | ||||
|  | ||||
| const CCreature* CCreatureSet::getCreature(TSlot slot) const | ||||
|   | ||||
| @@ -993,7 +993,7 @@ void CGameState::init(StartInfo * si) | ||||
| 		if(map->checksum != scenarioOps->mapfileChecksum) | ||||
| 		{ | ||||
| 			tlog1 << "Wrong map checksum!!!" << std::endl; | ||||
| 			throw std::string("Wrong checksum"); | ||||
| 			throw std::runtime_error("Wrong checksum"); | ||||
| 		} | ||||
| 	} | ||||
| 	else | ||||
|   | ||||
| @@ -49,7 +49,7 @@ int CHeroClass::chooseSecSkill(const std::set<int> & possibles) const //picks se | ||||
| 		if(ran<0) | ||||
| 			return *i; | ||||
| 	} | ||||
| 	throw std::string("Cannot pick secondary skill!"); | ||||
| 	throw std::runtime_error("Cannot pick secondary skill!"); | ||||
| } | ||||
|  | ||||
| EAlignment::EAlignment CHeroClass::getAlignment() | ||||
|   | ||||
| @@ -1433,7 +1433,7 @@ int CGHeroInstance::getBoatType() const | ||||
| 	case 2: | ||||
| 		return 2; | ||||
| 	default: | ||||
| 		throw std::string("Wrong alignment!"); | ||||
| 		throw std::runtime_error("Wrong alignment!"); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @@ -1679,7 +1679,7 @@ void CGDwelling::onHeroVisit( const CGHeroInstance * h ) const | ||||
| 	else if(ID == 106) | ||||
| 		bd.text.addTxt(MetaString::ADVOB_TXT, 157); //{War Machine Factory} Would you like to purchase War Machines? | ||||
| 	else | ||||
| 		throw std::string("Illegal dwelling!"); | ||||
| 		throw std::runtime_error("Illegal dwelling!"); | ||||
|  | ||||
| 	cb->showBlockingDialog(&bd, boost::bind(&CGDwelling::heroAcceptsCreatures, this, h, _1)); | ||||
| } | ||||
| @@ -2743,7 +2743,7 @@ const std::string & CGVisitableOPH::getHoverText() const | ||||
| 		pom = 10; | ||||
| 		break; | ||||
| 	default: | ||||
| 		throw std::string("Wrong CGVisitableOPH object ID!\n"); | ||||
| 		throw std::runtime_error("Wrong CGVisitableOPH object ID!\n"); | ||||
| 	} | ||||
| 	hoverName = VLC->generaltexth->names[ID]; | ||||
| 	if(pom >= 0) | ||||
| @@ -4037,7 +4037,7 @@ void CGPickable::chosen( int which, int heroID ) const | ||||
| 		cb->changePrimSkill(heroID, 4, h->calculateXp(val2)); | ||||
| 		break; | ||||
| 	default: | ||||
| 		throw std::string("Unhandled treasure choice"); | ||||
| 		throw std::runtime_error("Unhandled treasure choice"); | ||||
| 	} | ||||
| 	cb->removeObject(id); | ||||
| } | ||||
|   | ||||
| @@ -68,7 +68,7 @@ namespace SRSLPraserHelpers | ||||
| 		case 5: //left | ||||
| 			return std::make_pair(x-1, y); | ||||
| 		default: | ||||
| 			throw std::string("Disaster: wrong direction in SRSLPraserHelpers::gotoDir!\n"); | ||||
| 			throw std::runtime_error("Disaster: wrong direction in SRSLPraserHelpers::gotoDir!\n"); | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
|   | ||||
| @@ -133,7 +133,7 @@ connerror1: | ||||
| 		tlog1 << "No error info. " << std::endl; | ||||
| 	delete io_service; | ||||
| 	//delete socket;	 | ||||
| 	throw std::string("Can't establish connection :("); | ||||
| 	throw std::runtime_error("Can't establish connection :("); | ||||
| } | ||||
| CConnection::CConnection(TSocket * Socket, std::string Name ) | ||||
| 	:socket(Socket),io_service(&Socket->get_io_service()), name(Name)//, send(this), rec(this) | ||||
| @@ -150,7 +150,7 @@ CConnection::CConnection(TAcceptor * acceptor, boost::asio::io_service *Io_servi | ||||
| 	{  | ||||
| 		tlog1 << "Error on accepting: " << std::endl << error << std::endl; | ||||
| 		delete socket;	 | ||||
| 		throw "Can't establish connection :(";  | ||||
| 		throw std::runtime_error("Can't establish connection :(");  | ||||
| 	} | ||||
| 	init(); | ||||
| } | ||||
|   | ||||
| @@ -184,7 +184,7 @@ struct SaveWrong | ||||
| { | ||||
| 	static void invoke(Ser &s, const T &data) | ||||
| 	{ | ||||
| 		throw std::string("Wrong save serialization call!"); | ||||
| 		throw std::runtime_error("Wrong save serialization call!"); | ||||
| 	} | ||||
| }; | ||||
| template<typename Ser,typename T> | ||||
| @@ -192,7 +192,7 @@ struct LoadWrong | ||||
| { | ||||
| 	static void invoke(Ser &s, const T &data) | ||||
| 	{ | ||||
| 		throw std::string("Wrong load serialization call!"); | ||||
| 		throw std::runtime_error("Wrong load serialization call!"); | ||||
| 	} | ||||
| }; | ||||
|  | ||||
|   | ||||
| @@ -70,7 +70,7 @@ struct StartInfo | ||||
| 		if(playerInfos.find(no) != playerInfos.end()) | ||||
| 			return playerInfos[no]; | ||||
| 		tlog1 << "Cannot find info about player " << no <<". Throwing...\n"; | ||||
| 		throw std::string("Cannot find info about player"); | ||||
| 		throw std::runtime_error("Cannot find info about player"); | ||||
| 	} | ||||
|  | ||||
| 	PlayerSettings *getPlayersSettings(const ui8 nameID) | ||||
|   | ||||
| @@ -151,7 +151,7 @@ void CMapHeader::initFromMemory( const ui8 *bufor, int &i ) | ||||
| 	version = (Eformat)(read_le_u32(bufor + i)); i+=4; //map version | ||||
| 	if(version != RoE && version != AB && version != SoD && version != WoG) | ||||
| 	{ | ||||
| 		throw std::string("Invalid map format!"); | ||||
| 		throw std::runtime_error("Invalid map format!"); | ||||
| 	} | ||||
| 	areAnyPLayers = readChar(bufor,i); //invalid on some maps | ||||
| 	height = width = (read_le_u32(bufor + i)); i+=4; // dimensions of map | ||||
|   | ||||
| @@ -110,7 +110,7 @@ PlayerStatus PlayerStatuses::operator[](ui8 player) | ||||
| 	} | ||||
| 	else | ||||
| 	{ | ||||
| 		throw std::string("No such player!"); | ||||
| 		throw std::runtime_error("No such player!"); | ||||
| 	} | ||||
| } | ||||
| void PlayerStatuses::addPlayer(ui8 player) | ||||
| @@ -141,7 +141,7 @@ bool PlayerStatuses::checkFlag(ui8 player, bool PlayerStatus::*flag) | ||||
| 	} | ||||
| 	else | ||||
| 	{ | ||||
| 		throw std::string("No such player!"); | ||||
| 		throw std::runtime_error("No such player!"); | ||||
| 	} | ||||
| } | ||||
| void PlayerStatuses::setFlag(ui8 player, bool PlayerStatus::*flag, bool val) | ||||
| @@ -153,7 +153,7 @@ void PlayerStatuses::setFlag(ui8 player, bool PlayerStatus::*flag, bool val) | ||||
| 	} | ||||
| 	else | ||||
| 	{ | ||||
| 		throw std::string("No such player!"); | ||||
| 		throw std::runtime_error("No such player!"); | ||||
| 	} | ||||
| 	cv.notify_all(); | ||||
| } | ||||
| @@ -166,7 +166,7 @@ void PlayerStatuses::addQuery(ui8 player, ui32 id) | ||||
| 	} | ||||
| 	else | ||||
| 	{ | ||||
| 		throw std::string("No such player!"); | ||||
| 		throw std::runtime_error("No such player!"); | ||||
| 	} | ||||
| 	cv.notify_all(); | ||||
| } | ||||
| @@ -179,7 +179,7 @@ void PlayerStatuses::removeQuery(ui8 player, ui32 id) | ||||
| 	} | ||||
| 	else | ||||
| 	{ | ||||
| 		throw std::string("No such player!"); | ||||
| 		throw std::runtime_error("No such player!"); | ||||
| 	} | ||||
| 	cv.notify_all(); | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user