From 8aac13fe33638f87b8e95d49ac34a16ca4ae94cd Mon Sep 17 00:00:00 2001
From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz>
Date: Fri, 7 Nov 2014 22:21:24 +0100
Subject: [PATCH] add catch for std base exception and print unknown

---
 acat2/src/acat.cpp                 |  6 +++++-
 aconversions2/src/aconversion.cpp  | 16 ++++++++--------
 aconvert2/src/aconvert.cpp         |  6 +++++-
 aderivation2/src/aderivation.cpp   |  6 +++++-
 adeterminize2/src/adeterminize.cpp | 12 ++++++++----
 adiff2/src/adiff.cpp               | 12 ++++++++----
 aepsilon2/src/aepsilon.cpp         |  4 ++++
 aintegral2/src/aintegral.cpp       |  4 ++++
 aminimize2/src/aminimize.cpp       |  4 ++++
 anormalize2/src/anormalize.cpp     |  4 ++++
 arand2/src/arand.cpp               | 10 +++++++---
 arename2/src/arename.cpp           |  4 ++++
 arun2/src/arun.cpp                 | 10 +++++++---
 astat2/src/astat.cpp               | 10 +++++++---
 astringology2/src/astringology.cpp | 10 +++++++---
 atrim2/src/atrim.cpp               | 10 +++++++---
 16 files changed, 94 insertions(+), 34 deletions(-)

diff --git a/acat2/src/acat.cpp b/acat2/src/acat.cpp
index 2001a754e1..bfe0ad71fa 100644
--- a/acat2/src/acat.cpp
+++ b/acat2/src/acat.cpp
@@ -41,9 +41,13 @@ int main(int argc, char** argv) {
 		alib::DataFactory::toStdout(exception);
 		return 1;
 	} catch(const TCLAP::ArgException& exception) {
-		std::cout << exception.error() << std::endl;
+		std::cerr << exception.error() << std::endl;
 		return 2;
+	} catch (const std::exception& exception) {
+		std::cerr << "Exception caught: " << exception.what() << std::endl;
+		return 3;
 	} catch(...) {
+		std::cerr << "Unknown exception caught." << std::endl;
 		return 127;
 	}
 }
diff --git a/aconversions2/src/aconversion.cpp b/aconversions2/src/aconversion.cpp
index cccc2e9902..fa37f28c3e 100644
--- a/aconversions2/src/aconversion.cpp
+++ b/aconversions2/src/aconversion.cpp
@@ -97,8 +97,7 @@ int main(int argc, char* argv[])
 	int long_index = 0, opt = 0;
 	std::string target, algorithm;
 
-	while( ( opt = getopt_long( argc, argv,"a:t:vhl", long_options, & long_index ) )	!= -1 )
-	{
+	while( ( opt = getopt_long( argc, argv,"a:t:vhl", long_options, & long_index ) ) != -1 ) {
 		switch( opt )
 		{
 		case 'a':
@@ -118,8 +117,7 @@ int main(int argc, char* argv[])
 		}
 	}
 
-	try
-	{
+	try {
 		list<Token> tokens;
 		std::string input( istreambuf_iterator<char>( cin ), ( istreambuf_iterator<char>( ) ) );
 		SaxParseInterface::parseMemory( input, tokens );
@@ -129,12 +127,14 @@ int main(int argc, char* argv[])
 		ConversionHandler conv( tokens, target, algorithm, cout );
 		conv.convert( );
 		return 0;
-	}
-	catch( const exception::AlibException & exception ) {
+	} catch (const exception::AlibException & exception ) {
 		alib::DataFactory::toStdout(exception);
-		std::cout << exception << std::endl;
 		return 1;
-	} catch (...) {
+	} catch (const std::exception& exception) {
+		std::cerr << "Exception caught: " << exception.what() << std::endl;
+		return 3;
+	} catch(...) {
+		std::cerr << "Unknown exception caught." << std::endl;
 		return 127;
 	}
 }
diff --git a/aconvert2/src/aconvert.cpp b/aconvert2/src/aconvert.cpp
index f1c039a31c..b552cd1c8d 100644
--- a/aconvert2/src/aconvert.cpp
+++ b/aconvert2/src/aconvert.cpp
@@ -163,9 +163,13 @@ int main(int argc, char* argv[]) {
 		alib::DataFactory::toStdout(exception);
 		return 1;
 	} catch(const TCLAP::ArgException& exception) {
-		std::cout << exception.error() << std::endl;
+		std::cerr << exception.error() << std::endl;
 		return 2;
+	} catch (const std::exception& exception) {
+		std::cerr << "Exception caught: " << exception.what() << std::endl;
+		return 3;
 	} catch(...) {
+		std::cerr << "Unknown exception caught." << std::endl;
 		return 127;
 	}
 }
diff --git a/aderivation2/src/aderivation.cpp b/aderivation2/src/aderivation.cpp
index c1bfb1bb92..bd2592ac39 100644
--- a/aderivation2/src/aderivation.cpp
+++ b/aderivation2/src/aderivation.cpp
@@ -51,9 +51,13 @@ int main(int argc, char** argv) {
 		alib::DataFactory::toStdout(exception);
 		return 1;
 	} catch(const TCLAP::ArgException& exception) {
-		std::cout << exception.error() << std::endl;
+		std::cerr << exception.error() << std::endl;
 		return 2;
+	} catch (const std::exception& exception) {
+		std::cerr << "Exception caught: " << exception.what() << std::endl;
+		return 3;
 	} catch(...) {
+		std::cerr << "Unknown exception caught." << std::endl;
 		return 127;
 	}
 }
diff --git a/adeterminize2/src/adeterminize.cpp b/adeterminize2/src/adeterminize.cpp
index 49b0d77c53..566b92648f 100644
--- a/adeterminize2/src/adeterminize.cpp
+++ b/adeterminize2/src/adeterminize.cpp
@@ -34,13 +34,17 @@ int main(int argc, char** argv) {
 
 		alib::DataFactory::toStdout(automaton::determinize::Determinize::determinize(alib::DataFactory::fromTokens<automaton::Automaton>(tokens)));
 		return 0;
-	} catch (const exception::AlibException& e) {
-		alib::DataFactory::toStdout(e);
+	} catch (const exception::AlibException& exception) {
+		alib::DataFactory::toStdout(exception);
 		return 1;
 	} catch(const TCLAP::ArgException& exception) {
-		std::cout << exception.error() << std::endl;
+		std::cerr << exception.error() << std::endl;
 		return 2;
-	} catch (...) {
+	} catch (const std::exception& exception) {
+		std::cerr << "Exception caught: " << exception.what() << std::endl;
+		return 3;
+	} catch(...) {
+		std::cerr << "Unknown exception caught." << std::endl;
 		return 127;
 	}
 }
diff --git a/adiff2/src/adiff.cpp b/adiff2/src/adiff.cpp
index 3e63c36f18..84cbe67663 100644
--- a/adiff2/src/adiff.cpp
+++ b/adiff2/src/adiff.cpp
@@ -72,13 +72,17 @@ int main(int argc, char** argv) {
 		if(alib::api<exception::AlibException>::first(tokens2)) std::cout << alib::DataFactory::fromTokens<exception::AlibException>(tokens2).getCause() << std::endl;
 
 		return 2;
-	} catch (const exception::AlibException& e) {
-		std::cout << e.getCause() << std::endl;
+	} catch (const exception::AlibException& exception) {
+		alib::DataFactory::toStdout(exception);
 		return 1;
 	} catch(const TCLAP::ArgException& exception) {
-		std::cout << exception.error() << std::endl;
+		std::cerr << exception.error() << std::endl;
 		return 2;
-	} catch (...) {
+	} catch (const std::exception& exception) {
+		std::cerr << "Exception caught: " << exception.what() << std::endl;
+		return 3;
+	} catch(...) {
+		std::cerr << "Unknown exception caught." << std::endl;
 		return 127;
 	}
 }
diff --git a/aepsilon2/src/aepsilon.cpp b/aepsilon2/src/aepsilon.cpp
index 9498a4f31c..900d83656b 100644
--- a/aepsilon2/src/aepsilon.cpp
+++ b/aepsilon2/src/aepsilon.cpp
@@ -42,7 +42,11 @@ int main(int argc, char** argv) {
 	} catch(const TCLAP::ArgException& exception) {
 		std::cout << exception.error() << std::endl;
 		return 2;
+	} catch (const std::exception& exception) {
+		std::cerr << "Exception caught: " << exception.what() << std::endl;
+		return 3;
 	} catch(...) {
+		std::cerr << "Unknown exception caught." << std::endl;
 		return 127;
 	}
 }
diff --git a/aintegral2/src/aintegral.cpp b/aintegral2/src/aintegral.cpp
index dd2d74e696..71813ec0b0 100644
--- a/aintegral2/src/aintegral.cpp
+++ b/aintegral2/src/aintegral.cpp
@@ -53,7 +53,11 @@ int main(int argc, char** argv) {
 	} catch(const TCLAP::ArgException& exception) {
 		std::cout << exception.error() << std::endl;
 		return 2;
+	} catch (const std::exception& exception) {
+		std::cerr << "Exception caught: " << exception.what() << std::endl;
+		return 3;
 	} catch(...) {
+		std::cerr << "Unknown exception caught." << std::endl;
 		return 127;
 	}
 }
diff --git a/aminimize2/src/aminimize.cpp b/aminimize2/src/aminimize.cpp
index cba10710ad..3a6c226ecf 100644
--- a/aminimize2/src/aminimize.cpp
+++ b/aminimize2/src/aminimize.cpp
@@ -42,7 +42,11 @@ int main(int argc, char** argv) {
 	} catch(const TCLAP::ArgException& exception) {
 		std::cout << exception.error() << std::endl;
 		return 2;
+	} catch (const std::exception& exception) {
+		std::cerr << "Exception caught: " << exception.what() << std::endl;
+		return 3;
 	} catch(...) {
+		std::cerr << "Unknown exception caught." << std::endl;
 		return 127;
 	}
 }
diff --git a/anormalize2/src/anormalize.cpp b/anormalize2/src/anormalize.cpp
index e5bfc4b5ba..eda475aa21 100644
--- a/anormalize2/src/anormalize.cpp
+++ b/anormalize2/src/anormalize.cpp
@@ -41,7 +41,11 @@ int main(int argc, char** argv) {
 	} catch(const TCLAP::ArgException& exception) {
 		std::cout << exception.error() << std::endl;
 		return 2;
+	} catch (const std::exception& exception) {
+		std::cerr << "Exception caught: " << exception.what() << std::endl;
+		return 3;
 	} catch(...) {
+		std::cerr << "Unknown exception caught." << std::endl;
 		return 127;
 	}
 }
diff --git a/arand2/src/arand.cpp b/arand2/src/arand.cpp
index 1096b6a6f9..12da4087e3 100644
--- a/arand2/src/arand.cpp
+++ b/arand2/src/arand.cpp
@@ -72,13 +72,17 @@ int main(int argc, char* argv[]) {
 		}
 
 		return 0;
-	} catch( const exception::AlibException & e ) {
-		alib::DataFactory::toStdout( e );
+	} catch( const exception::AlibException & exception ) {
+		alib::DataFactory::toStdout( exception );
 		return 1;
 	} catch(const TCLAP::ArgException& exception) {
 		std::cout << exception.error() << std::endl;
 		return 2;
-	} catch (...) {
+	} catch (const std::exception& exception) {
+		std::cerr << "Exception caught: " << exception.what() << std::endl;
+		return 3;
+	} catch(...) {
+		std::cerr << "Unknown exception caught." << std::endl;
 		return 127;
 	}
 }
diff --git a/arename2/src/arename.cpp b/arename2/src/arename.cpp
index fc81b088cb..14b16c3658 100644
--- a/arename2/src/arename.cpp
+++ b/arename2/src/arename.cpp
@@ -41,7 +41,11 @@ int main(int argc, char** argv) {
 	} catch(const TCLAP::ArgException& exception) {
 		std::cout << exception.error() << std::endl;
 		return 2;
+	} catch (const std::exception& exception) {
+		std::cerr << "Exception caught: " << exception.what() << std::endl;
+		return 3;
 	} catch(...) {
+		std::cerr << "Unknown exception caught." << std::endl;
 		return 127;
 	}
 }
diff --git a/arun2/src/arun.cpp b/arun2/src/arun.cpp
index dfe6c9d39d..69cbad7756 100644
--- a/arun2/src/arun.cpp
+++ b/arun2/src/arun.cpp
@@ -72,13 +72,17 @@ int main(int argc, char* argv[]) {
 			throw exception::AlibException( "Invalid run type" );
 			return 1;
 		}
-	} catch( const exception::AlibException & e ) {
-		alib::DataFactory::toStdout( e );
+	} catch( const exception::AlibException & exception ) {
+		alib::DataFactory::toStdout( exception );
 		return 1;
 	} catch(const TCLAP::ArgException& exception) {
 		std::cout << exception.error() << std::endl;
 		return 2;
-	} catch (...) {
+	} catch (const std::exception& exception) {
+		std::cerr << "Exception caught: " << exception.what() << std::endl;
+		return 3;
+	} catch(...) {
+		std::cerr << "Unknown exception caught." << std::endl;
 		return 127;
 	}
 }
diff --git a/astat2/src/astat.cpp b/astat2/src/astat.cpp
index 3b2dffd084..03de60fcec 100644
--- a/astat2/src/astat.cpp
+++ b/astat2/src/astat.cpp
@@ -136,13 +136,17 @@ int main(int argc, char* argv[]) {
 			throw exception::AlibException( "Input not recognized." );
 			return 1;
 		}
-	} catch( const exception::AlibException & e ) {
-		alib::DataFactory::toStdout( e );
+	} catch( const exception::AlibException & exception ) {
+		alib::DataFactory::toStdout( exception );
 		return 1;
 	} catch(const TCLAP::ArgException& exception) {
 		std::cout << exception.error() << std::endl;
 		return 2;
-	} catch (...) {
+	} catch (const std::exception& exception) {
+		std::cerr << "Exception caught: " << exception.what() << std::endl;
+		return 3;
+	} catch(...) {
+		std::cerr << "Unknown exception caught." << std::endl;
 		return 127;
 	}
 }
diff --git a/astringology2/src/astringology.cpp b/astringology2/src/astringology.cpp
index 35c67edbab..65029862d9 100644
--- a/astringology2/src/astringology.cpp
+++ b/astringology2/src/astringology.cpp
@@ -72,13 +72,17 @@ int main(int argc, char* argv[]) {
 			throw exception::AlibException( "Invalid algorithm" );
 			return 1;
 		}
-	} catch( const exception::AlibException & e ) {
-		alib::DataFactory::toStdout( e );
+	} catch( const exception::AlibException & exception ) {
+		alib::DataFactory::toStdout( exception );
 		return 1;
 	} catch(const TCLAP::ArgException& exception) {
 		std::cout << exception.error() << std::endl;
 		return 2;
-	} catch (...) {
+	} catch (const std::exception& exception) {
+		std::cerr << "Exception caught: " << exception.what() << std::endl;
+		return 3;
+	} catch(...) {
+		std::cerr << "Unknown exception caught." << std::endl;
 		return 127;
 	}
 }
diff --git a/atrim2/src/atrim.cpp b/atrim2/src/atrim.cpp
index ea04560a24..a74effd36c 100644
--- a/atrim2/src/atrim.cpp
+++ b/atrim2/src/atrim.cpp
@@ -98,13 +98,17 @@ int main(int argc, char* argv[]) {
 			throw exception::AlibException( "Input not recognized." );
 			return 1;
 		}
-	} catch( const exception::AlibException & e ) {
-		alib::DataFactory::toStdout( e );
+	} catch( const exception::AlibException & exception ) {
+		alib::DataFactory::toStdout( exception );
 		return 1;
 	} catch(const TCLAP::ArgException& exception) {
 		std::cout << exception.error() << std::endl;
 		return 2;
-	} catch (...) {
+	} catch (const std::exception& exception) {
+		std::cerr << "Exception caught: " << exception.what() << std::endl;
+		return 3;
+	} catch(...) {
+		std::cerr << "Unknown exception caught." << std::endl;
 		return 127;
 	}
 }
-- 
GitLab