Commits

Wei Cheng Pan committed 68862ea

Apply exceptions.

Comments (0)

Files changed (4)

Krapture/client/src/Command/CommandParser.cpp

 #include "CommandParser_p.hpp"
-#include "Network/TCPMessage.hpp"
 
+#include "xTitan/Exception/NetworkError.hpp"
+
+#include "Network/TCPMessage.hpp"
 #include "InputCommand.hpp"
 #include "SuccessCommand.hpp"
 #include "FailCommand.hpp"
 #include "QuitCommand.hpp"
 
-#include <cassert>
 
 using namespace xtitan::command;
+using xtitan::NetworkError;
+
 
 CommandParser::Private::Private():
 commandList() {
 	if( it != this->p_->commandList.end() ) {
 		it.value()->execute( data );
 	} else {
-		//throw an exception
-		assert( !"WRONG PROTOCOL COMMAND!" );
+		throw NetworkError( QObject::tr( "wrong protocol command: %1" ).arg( header ) );
 	}
 }

Krapture/client/src/Command/InputCommand.cpp

 #include "InputCommand.hpp"
 
-#include <cassert>
-
 #include <QtCore/QMetaObject>
 
+#include "xTitan/Exception/NetworkError.hpp"
 #include "xTitan/Spy/Spy.hpp"
 
+
 using namespace xtitan::command;
 using xtitan::Spy;
 
+
 // format: script
 void InputCommand::execute( const QVariant & data ) {
 	auto kwargs = data.toMap();
 			auto s = it->toString();
 			sArgs.append( QString( "\'%1\'" ).arg( s ) );
 		} else {
-			// never happen
-			assert( !"wrong command" );
+			throw NetworkError( QObject::tr( "unknown data type: %1" ).arg( it->typeName() ) );
 		}
 	}
 

Krapture/client/src/Spy/Spy.cpp

 #include "Spy/Spy_p.hpp"
 
-#include <cassert>
-
 #include <QtCore/QDateTime>
 #include <QtNetwork/QHostAddress>
 
 		this->p_->engine->evaluate( script );
 	} else {
 		this->p_->engine->clearExceptions();
-		assert( !"INVALID SCRIPT" );
+		// TODO send warning
 	}
 }
 

Krapture/client/src/Spy/SpyModel.cpp

 #include "Spy/SpyModel_p.hpp"
 
-#include <cassert>
-
+#include "xTitan/Exception/NetworkError.hpp"
 #include "Network/TcpMessageComposer.hpp"
 #include "xTitan/Spy/Spy.hpp"
 
+
 using xtitan::SpyModel;
 using xtitan::SimpleSocket;
 using xtitan::command::CommandParser;
 
+
 SpyModel::Private::Private( SpyModel * host ):
 QObject( host ),
 socket( new SimpleSocket( this ) ),
 }
 
 void SpyModel::Private::send( const QxPacket & pkt ) {
-	assert( this->socket->state() == QLocalSocket::ConnectedState );
+	if( this->socket->state() != QLocalSocket::ConnectedState ) {
+		throw NetworkError( "disconnected from server, send failed" );
+	}
 	this->socket->write( pkt.first, pkt.second );
 }