THRIFT-2015 Thrift exceptions should derive from TException
authorJens Geyer <jensg@apache.org>
Wed, 12 Jun 2013 19:09:36 +0000 (21:09 +0200)
committerJens Geyer <jensg@apache.org>
Wed, 12 Jun 2013 19:10:35 +0000 (21:10 +0200)
Patch: Jens Geyer

compiler/cpp/src/generate/t_csharp_generator.cc
lib/csharp/src/Protocol/TProtocolException.cs
lib/csharp/src/TApplicationException.cs
lib/csharp/src/TException.cs [new file with mode: 0644]
lib/csharp/src/Thrift.WP7.csproj
lib/csharp/src/Thrift.csproj
lib/csharp/src/Transport/TTransportException.cs

index 016e3f8..37800a5 100644 (file)
@@ -514,7 +514,7 @@ void t_csharp_generator::generate_csharp_struct_definition(ofstream &out, t_stru
   indent(out) << "public " << (is_final ? "sealed " : "") << "partial class " << tstruct->get_name() << " : ";
 
   if (is_exception) {
-    out << "Exception, ";
+    out << "TException, ";
   }
   out << "TBase";
 
@@ -997,7 +997,7 @@ void t_csharp_generator::generate_csharp_union_definition(std::ofstream& out, t_
 
   indent(out) << "public override void Write(TProtocol protocol) {" << endl;
   indent_up();
-  indent(out) << "throw new Exception(\"Cannot persist an union type which is not set.\");" << endl;
+  indent(out) << "throw new TProtocolException( TProtocolException.INVALID_DATA, \"Cannot persist an union type which is not set.\");" << endl;
   indent_down();
   indent(out) << "}" << endl << endl;
 
index 4e4393f..bc002d3 100644 (file)
@@ -25,7 +25,7 @@ using System;
 
 namespace Thrift.Protocol
 {
-       public class TProtocolException : Exception
+       public class TProtocolException : TException
        {
                public const int UNKNOWN = 0;
                public const int INVALID_DATA = 1;
index 9aaf6f7..4a1b2d2 100644 (file)
@@ -26,7 +26,7 @@ using Thrift.Protocol;
 
 namespace Thrift
 {
-       public class TApplicationException : Exception
+       public class TApplicationException : TException
        {
                protected ExceptionType type;
 
diff --git a/lib/csharp/src/TException.cs b/lib/csharp/src/TException.cs
new file mode 100644 (file)
index 0000000..a99bfa8
--- /dev/null
@@ -0,0 +1,40 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ * Contains some contributions under the Thrift Software License.
+ * Please see doc/old-thrift-license.txt in the Thrift distribution for
+ * details.
+ */
+
+using System;
+
+namespace Thrift
+{
+       public class TException : Exception
+       {
+               public TException()
+               {
+               }
+
+               public TException( string message)
+                       : base(message)
+               {
+               }
+
+       }
+}
index e9dc494..2b2147e 100644 (file)
@@ -93,6 +93,7 @@
     <Compile Include="Protocol\TSet.cs" />
     <Compile Include="Protocol\TStruct.cs" />
     <Compile Include="Protocol\TType.cs" />
+    <Compile Include="TException.cs" />
     <Compile Include="TApplicationException.cs" />
     <Compile Include="TProcessor.cs" />
     <Compile Include="Transport\TFramedTransport.cs" />
index cb264c8..439b960 100644 (file)
     <Compile Include="Server\TServer.cs" />\r
     <Compile Include="Server\TSimpleServer.cs" />\r
     <Compile Include="Server\TThreadPoolServer.cs" />\r
+    <Compile Include="TException.cs" />\r
     <Compile Include="TApplicationException.cs" />\r
     <Compile Include="TProcessor.cs" />\r
     <Compile Include="Transport\TBufferedTransport.cs" />\r
index b96f7e8..fda0138 100644 (file)
@@ -25,7 +25,7 @@ using System;
 
 namespace Thrift.Transport
 {
-       public class TTransportException : Exception
+       public class TTransportException : TException
        {
                protected ExceptionType type;