From b310ae78160bf95f6c49ed1cb13aea609878f6ee Mon Sep 17 00:00:00 2001 From: Jens Geyer Date: Wed, 12 Jun 2013 21:09:36 +0200 Subject: [PATCH] THRIFT-2015 Thrift exceptions should derive from TException Patch: Jens Geyer --- .../cpp/src/generate/t_csharp_generator.cc | 4 +- lib/csharp/src/Protocol/TProtocolException.cs | 2 +- lib/csharp/src/TApplicationException.cs | 2 +- lib/csharp/src/TException.cs | 40 +++++++++++++++++++ lib/csharp/src/Thrift.WP7.csproj | 1 + lib/csharp/src/Thrift.csproj | 1 + .../src/Transport/TTransportException.cs | 2 +- 7 files changed, 47 insertions(+), 5 deletions(-) create mode 100644 lib/csharp/src/TException.cs diff --git a/compiler/cpp/src/generate/t_csharp_generator.cc b/compiler/cpp/src/generate/t_csharp_generator.cc index 016e3f8b..37800a5c 100644 --- a/compiler/cpp/src/generate/t_csharp_generator.cc +++ b/compiler/cpp/src/generate/t_csharp_generator.cc @@ -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; diff --git a/lib/csharp/src/Protocol/TProtocolException.cs b/lib/csharp/src/Protocol/TProtocolException.cs index 4e4393f9..bc002d3c 100644 --- a/lib/csharp/src/Protocol/TProtocolException.cs +++ b/lib/csharp/src/Protocol/TProtocolException.cs @@ -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; diff --git a/lib/csharp/src/TApplicationException.cs b/lib/csharp/src/TApplicationException.cs index 9aaf6f7f..4a1b2d23 100644 --- a/lib/csharp/src/TApplicationException.cs +++ b/lib/csharp/src/TApplicationException.cs @@ -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 index 00000000..a99bfa89 --- /dev/null +++ b/lib/csharp/src/TException.cs @@ -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) + { + } + + } +} diff --git a/lib/csharp/src/Thrift.WP7.csproj b/lib/csharp/src/Thrift.WP7.csproj index e9dc4942..2b2147e5 100644 --- a/lib/csharp/src/Thrift.WP7.csproj +++ b/lib/csharp/src/Thrift.WP7.csproj @@ -93,6 +93,7 @@ + diff --git a/lib/csharp/src/Thrift.csproj b/lib/csharp/src/Thrift.csproj index cb264c8f..439b960f 100644 --- a/lib/csharp/src/Thrift.csproj +++ b/lib/csharp/src/Thrift.csproj @@ -105,6 +105,7 @@ + diff --git a/lib/csharp/src/Transport/TTransportException.cs b/lib/csharp/src/Transport/TTransportException.cs index b96f7e87..fda0138f 100644 --- a/lib/csharp/src/Transport/TTransportException.cs +++ b/lib/csharp/src/Transport/TTransportException.cs @@ -25,7 +25,7 @@ using System; namespace Thrift.Transport { - public class TTransportException : Exception + public class TTransportException : TException { protected ExceptionType type; -- 2.17.1