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;