THRIFT-1293. cpp: improve handling of exceptions thrown by
process()
Patch: Adam Simpkins
git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1161660 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/cpp/src/server/TNonblockingServer.cpp b/lib/cpp/src/server/TNonblockingServer.cpp
index 681cbdb..a081077 100644
--- a/lib/cpp/src/server/TNonblockingServer.cpp
+++ b/lib/cpp/src/server/TNonblockingServer.cpp
@@ -78,15 +78,16 @@
break;
}
}
- } catch (TTransportException& ttx) {
- cerr << "TNonblockingServer client died: " << ttx.what() << endl;
- } catch (TException& x) {
- cerr << "TNonblockingServer exception: " << x.what() << endl;
- } catch (bad_alloc&) {
- cerr << "TNonblockingServer caught bad_alloc exception.";
+ } catch (const TTransportException& ttx) {
+ GlobalOutput.printf("TNonblockingServer client died: %s", ttx.what());
+ } catch (const bad_alloc&) {
+ GlobalOutput("TNonblockingServer caught bad_alloc exception.");
exit(-1);
+ } catch (const std::exception& x) {
+ GlobalOutput.printf("TNonblockingServer process() exception: %s: %s",
+ typeid(x).name(), x.what());
} catch (...) {
- cerr << "TNonblockingServer uncaught exception." << endl;
+ GlobalOutput("TNonblockingServer uncaught exception.");
}
// Signal completion back to the libevent thread via a pipe
@@ -320,13 +321,15 @@
try {
// Invoke the processor
server_->getProcessor()->process(inputProtocol_, outputProtocol_, NULL);
- } catch (TTransportException &ttx) {
- GlobalOutput.printf("TTransportException: Server::process() %s", ttx.what());
+ } catch (const TTransportException &ttx) {
+ GlobalOutput.printf("TNonblockingServer transport error in "
+ "process(): %s", ttx.what());
server_->decrementActiveProcessors();
close();
return;
- } catch (TException &x) {
- GlobalOutput.printf("TException: Server::process() %s", x.what());
+ } catch (const std::exception &x) {
+ GlobalOutput.printf("Server::process() uncaught exception: %s: %s",
+ typeid(x).name(), x.what());
server_->decrementActiveProcessors();
close();
return;
diff --git a/lib/cpp/src/server/TSimpleServer.cpp b/lib/cpp/src/server/TSimpleServer.cpp
index c0fd67c..0e5a967 100644
--- a/lib/cpp/src/server/TSimpleServer.cpp
+++ b/lib/cpp/src/server/TSimpleServer.cpp
@@ -102,12 +102,12 @@
break;
}
}
- } catch (TTransportException& ttx) {
+ } catch (const TTransportException& ttx) {
string errStr = string("TSimpleServer client died: ") + ttx.what();
GlobalOutput(errStr.c_str());
- } catch (TException& tx) {
- string errStr = string("TSimpleServer exception: ") + tx.what();
- GlobalOutput(errStr.c_str());
+ } catch (const std::exception& x) {
+ GlobalOutput.printf("TSimpleServer exception: %s: %s",
+ typeid(x).name(), x.what());
} catch (...) {
GlobalOutput("TSimpleServer uncaught exception.");
}
diff --git a/lib/cpp/src/server/TThreadPoolServer.cpp b/lib/cpp/src/server/TThreadPoolServer.cpp
index 840b835..2204076 100644
--- a/lib/cpp/src/server/TThreadPoolServer.cpp
+++ b/lib/cpp/src/server/TThreadPoolServer.cpp
@@ -68,17 +68,14 @@
break;
}
}
- } catch (TTransportException& ttx) {
+ } catch (const TTransportException& ttx) {
// This is reasonably expected, client didn't send a full request so just
// ignore him
// string errStr = string("TThreadPoolServer client died: ") + ttx.what();
// GlobalOutput(errStr.c_str());
- } catch (TException& x) {
- string errStr = string("TThreadPoolServer exception: ") + x.what();
- GlobalOutput(errStr.c_str());
- } catch (std::exception &x) {
- string errStr = string("TThreadPoolServer, std::exception: ") + x.what();
- GlobalOutput(errStr.c_str());
+ } catch (const std::exception& x) {
+ GlobalOutput.printf("TThreadPoolServer exception %s: %s",
+ typeid(x).name(), x.what());
} catch (...) {
GlobalOutput("TThreadPoolServer, unexpected exception in "
"TThreadPoolServer::Task::run()");
diff --git a/lib/cpp/src/server/TThreadedServer.cpp b/lib/cpp/src/server/TThreadedServer.cpp
index b1ef1e0..feeb0e9 100644
--- a/lib/cpp/src/server/TThreadedServer.cpp
+++ b/lib/cpp/src/server/TThreadedServer.cpp
@@ -70,14 +70,14 @@
break;
}
}
- } catch (TTransportException& ttx) {
+ } catch (const TTransportException& ttx) {
if (ttx.getType() != TTransportException::END_OF_FILE) {
string errStr = string("TThreadedServer client died: ") + ttx.what();
GlobalOutput(errStr.c_str());
}
- } catch (TException& x) {
- string errStr = string("TThreadedServer exception: ") + x.what();
- GlobalOutput(errStr.c_str());
+ } catch (const std::exception &x) {
+ GlobalOutput.printf("TThreadedServer exception: %s: %s",
+ typeid(x).name(), x.what());
} catch (...) {
GlobalOutput("TThreadedServer uncaught exception.");
}