Various Thrift fixes, including Application Exception support in Ruby, better errror messages across languages, etc.

Reviewed By: thrift


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665058 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/php/src/transport/TPhpStream.php b/lib/php/src/transport/TPhpStream.php
index 8a4fb0a..03837a8 100644
--- a/lib/php/src/transport/TPhpStream.php
+++ b/lib/php/src/transport/TPhpStream.php
@@ -40,13 +40,13 @@
     if ($this->read_) {
       $this->inStream_ = @fopen('php://input', 'r');
       if (!is_resource($this->inStream_)) {
-        throw new Exception('TPhpStream: Could not open php://input');
+        throw new TException('TPhpStream: Could not open php://input');
       }
     }
     if ($this->write_) {
       $this->outStream_ = @fopen('php://output', 'w');
       if (!is_resource($this->outStream_)) {
-        throw new Exception('TPhpStream: Could not open php://output');
+        throw new TException('TPhpStream: Could not open php://output');
       }
     }
   }
@@ -71,7 +71,7 @@
   public function read($len) {
     $data = @fread($this->inStream_, $len);
     if (!$data) {
-      throw new Exception('TPhpStream: Could not read '.$len.' bytes');
+      throw new TException('TPhpStream: Could not read '.$len.' bytes');
     }
     return $data;
   }
@@ -80,7 +80,7 @@
     while (strlen($buf) > 0) {
       $got = @fwrite($this->outStream_, $buf);
       if ($got === 0 || $got === FALSE) {
-        throw new Exception('TPhpStream: Could not write '.strlen($buf).' bytes');
+        throw new TException('TPhpStream: Could not write '.strlen($buf).' bytes');
       }
       $buf = substr($buf, $got);
     }
diff --git a/lib/php/src/transport/TSocket.php b/lib/php/src/transport/TSocket.php
index 1600b6f..cce3a44 100644
--- a/lib/php/src/transport/TSocket.php
+++ b/lib/php/src/transport/TSocket.php
@@ -160,7 +160,7 @@
       if ($this->debug_) {
         call_user_func($this->debugHandler_, $error);
       }
-      throw new Exception($error);
+      throw new TException($error);
     }
     
     stream_set_timeout($this->handle_, 0, $this->sendTimeout_*1000);
@@ -197,17 +197,17 @@
       if ($buf === FALSE || $buf === '') {
         $md = stream_get_meta_data($this->handle_);
         if ($md['timed_out']) {
-          throw new Exception('TSocket: timed out reading '.$len.' bytes from '.
-                              $this->host_.':'.$this->port_);
+          throw new TException('TSocket: timed out reading '.$len.' bytes from '.
+                               $this->host_.':'.$this->port_);
         } else {
-          throw new Exception('TSocket: Could not read '.$len.' bytes from '.
-                              $this->host_.':'.$this->port_);
+          throw new TException('TSocket: Could not read '.$len.' bytes from '.
+                               $this->host_.':'.$this->port_);
         }
       } else if (($sz = strlen($buf)) < $len) {
         $md = stream_get_meta_data($this->handle_);
         if ($md['timed_out']) {
-          throw new Exception('TSocket: timed out reading '.$len.' bytes from '.
-                              $this->host_.':'.$this->port_);
+          throw new TException('TSocket: timed out reading '.$len.' bytes from '.
+                               $this->host_.':'.$this->port_);
         } else {
           $pre .= $buf;
           $len -= $sz;
@@ -233,11 +233,11 @@
     if ($data === FALSE || $data === '') {
       $md = stream_get_meta_data($this->handle_);
       if ($md['timed_out']) {
-        throw new Exception('TSocket: timed out reading '.$len.' bytes from '.
-                            $this->host_.':'.$this->port_);
+        throw new TException('TSocket: timed out reading '.$len.' bytes from '.
+                             $this->host_.':'.$this->port_);
       } else {
-        throw new Exception('TSocket: Could not read '.$len.' bytes from '.
-                            $this->host_.':'.$this->port_);
+        throw new TException('TSocket: Could not read '.$len.' bytes from '.
+                             $this->host_.':'.$this->port_);
       }
     }
     return $data;
@@ -258,11 +258,11 @@
       if ($got === 0 || $got === FALSE) {
         $md = stream_get_meta_data($this->handle_);
         if ($md['timed_out']) {
-          throw new Exception('TSocket: timed out writing '.$len.' bytes from '.
-                              $this->host_.':'.$this->port_);
+          throw new TException('TSocket: timed out writing '.$len.' bytes from '.
+                               $this->host_.':'.$this->port_);
         } else {
-            throw new Exception('TSocket: Could not write '.strlen($buf).' bytes '.
-                                $this->host_.':'.$this->port_);
+            throw new TException('TSocket: Could not write '.strlen($buf).' bytes '.
+                                 $this->host_.':'.$this->port_);
         }
       }
       $buf = substr($buf, $got);
@@ -275,8 +275,8 @@
   public function flush() {
     $ret = fflush($this->handle_);
     if ($ret === FALSE) {
-      throw new Exception('TSocket: Could not flush: '.
-                          $this->host_.':'.$this->port_);
+      throw new TException('TSocket: Could not flush: '.
+                           $this->host_.':'.$this->port_);
     }
   }
 }
diff --git a/lib/php/src/transport/TSocketPool.php b/lib/php/src/transport/TSocketPool.php
index 9e5ebcd..b3efb2d 100644
--- a/lib/php/src/transport/TSocketPool.php
+++ b/lib/php/src/transport/TSocketPool.php
@@ -221,7 +221,7 @@
             // Successful connection, return now
             return;
 
-          } catch (Exception $x) {
+          } catch (TException $tx) {
             // Connection failed
           }
         }
@@ -268,7 +268,7 @@
     if ($this->debug_) {
       call_user_func($this->debugHandler_, $error);
     }
-    throw new Exception($error);
+    throw new TException($error);
   }
 }