From 377c5a48746b015036f6300cc30d2e9f0719e543 Mon Sep 17 00:00:00 2001
From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz>
Date: Thu, 14 Apr 2016 21:41:47 +0200
Subject: [PATCH] simplify exceptions handling

---
 acompare2/src/acompare.cpp               | 8 --------
 alib2data/src/factory/XmlDataFactory.hpp | 2 ++
 2 files changed, 2 insertions(+), 8 deletions(-)

diff --git a/acompare2/src/acompare.cpp b/acompare2/src/acompare.cpp
index 79fee62b12..36ee75972f 100644
--- a/acompare2/src/acompare.cpp
+++ b/acompare2/src/acompare.cpp
@@ -47,14 +47,6 @@ int main(int argc, char** argv) {
 		std::deque<sax::Token> tokens1 = sax::FromXMLParserHelper::parseInput(input1);
 		std::deque<sax::Token> tokens2 = sax::FromXMLParserHelper::parseInput(input2);
 
-		if (tokens1.empty() && tokens2.empty()) throw exception::CommonException("Invalid arguments tokens streams 1 and 2 are empty.");
-		if (tokens1.empty()) throw exception::CommonException("Invalid arguments tokens stream 1 is empty.");
-		if (tokens2.empty()) throw exception::CommonException("Invalid arguments tokens stream 2 is empty.");
-
-		if(alib::XmlDataFactory::first<exception::CommonException>(tokens1)) std::cerr << alib::XmlDataFactory::fromTokens<exception::CommonException>(std::move(tokens1)).getCause() << std::endl; //TODO is this realy needed?
-		if(alib::XmlDataFactory::first<exception::CommonException>(tokens2)) std::cerr << alib::XmlDataFactory::fromTokens<exception::CommonException>(std::move(tokens2)).getCause() << std::endl;
-		if(alib::XmlDataFactory::first<exception::CommonException>(tokens1) || alib::XmlDataFactory::first<exception::CommonException>(tokens2)) return 0;
-
 		int res;
 
 		if(alib::XmlDataFactory::first<automaton::Automaton>(tokens1) && alib::XmlDataFactory::first<automaton::Automaton>(tokens2)) {
diff --git a/alib2data/src/factory/XmlDataFactory.hpp b/alib2data/src/factory/XmlDataFactory.hpp
index ea0d5e1806..ddb301fb71 100644
--- a/alib2data/src/factory/XmlDataFactory.hpp
+++ b/alib2data/src/factory/XmlDataFactory.hpp
@@ -104,6 +104,8 @@ public:
 	 */
 	template < class T >
 	static bool first ( const std::deque < sax::Token > & tokens ) {
+		if( tokens.empty ( ) ) throw exception::CommonException ( "Empty tokens list" );
+
 		return alib::xmlApi < exception::CommonException >::first ( tokens.begin ( ) ) || alib::xmlApi < T >::first ( tokens.begin ( ) );
 	}
 
-- 
GitLab