THRIFT-4609 keep InnerException wherever appropriate
Client: C#
Patch: Jens Geyer
This closes #1576
diff --git a/lib/csharp/src/Protocol/TJSONProtocol.cs b/lib/csharp/src/Protocol/TJSONProtocol.cs
index 3390dc0..9dbdea9 100644
--- a/lib/csharp/src/Protocol/TJSONProtocol.cs
+++ b/lib/csharp/src/Protocol/TJSONProtocol.cs
@@ -859,19 +859,21 @@
{
ReadJSONSyntaxChar(QUOTE);
}
+
string str = ReadJSONNumericChars();
if (context.EscapeNumbers())
{
ReadJSONSyntaxChar(QUOTE);
}
+
try
{
return Int64.Parse(str);
}
- catch (FormatException)
+ catch (FormatException fex)
{
throw new TProtocolException(TProtocolException.INVALID_DATA,
- "Bad data encounted in numeric data");
+ "Bad data encounted in numeric data", fex);
}
}
@@ -887,8 +889,7 @@
byte[] arr = ReadJSONString(true);
double dub = Double.Parse(utf8Encoding.GetString(arr, 0, arr.Length), CultureInfo.InvariantCulture);
- if (!context.EscapeNumbers() && !Double.IsNaN(dub) &&
- !Double.IsInfinity(dub))
+ if (!context.EscapeNumbers() && !Double.IsNaN(dub) && !Double.IsInfinity(dub))
{
// Throw exception -- we should not be in a string in this case
throw new TProtocolException(TProtocolException.INVALID_DATA,
@@ -907,10 +908,10 @@
{
return Double.Parse(ReadJSONNumericChars(), CultureInfo.InvariantCulture);
}
- catch (FormatException)
+ catch (FormatException fex)
{
throw new TProtocolException(TProtocolException.INVALID_DATA,
- "Bad data encounted in numeric data");
+ "Bad data encounted in numeric data", fex);
}
}
}
diff --git a/lib/csharp/src/Protocol/TProtocolException.cs b/lib/csharp/src/Protocol/TProtocolException.cs
index a89c3fc..c0f007e 100644
--- a/lib/csharp/src/Protocol/TProtocolException.cs
+++ b/lib/csharp/src/Protocol/TProtocolException.cs
@@ -48,14 +48,14 @@
type_ = type;
}
- public TProtocolException(int type, string message)
- : base(message)
+ public TProtocolException(int type, string message, Exception inner = null)
+ : base(message, inner)
{
type_ = type;
}
- public TProtocolException(string message)
- : base(message)
+ public TProtocolException(string message, Exception inner = null)
+ : base(message, inner)
{
}
diff --git a/lib/csharp/src/TApplicationException.cs b/lib/csharp/src/TApplicationException.cs
index 0c5b08b..8dd7ae5 100644
--- a/lib/csharp/src/TApplicationException.cs
+++ b/lib/csharp/src/TApplicationException.cs
@@ -40,7 +40,7 @@
}
public TApplicationException(ExceptionType type, string message)
- : base(message)
+ : base(message, null) // TApplicationException is serializable, but we never serialize InnerException
{
this.type = type;
}
diff --git a/lib/csharp/src/TException.cs b/lib/csharp/src/TException.cs
index 35193c5..aa9a210 100644
--- a/lib/csharp/src/TException.cs
+++ b/lib/csharp/src/TException.cs
@@ -31,8 +31,8 @@
{
}
- public TException(string message)
- : base(message)
+ public TException(string message, Exception inner)
+ : base(message, inner)
{
}
diff --git a/lib/csharp/src/Transport/THttpClient.cs b/lib/csharp/src/Transport/THttpClient.cs
index 06ed6bc..667fc25 100644
--- a/lib/csharp/src/Transport/THttpClient.cs
+++ b/lib/csharp/src/Transport/THttpClient.cs
@@ -139,7 +139,7 @@
}
catch (IOException iox)
{
- throw new TTransportException(TTransportException.ExceptionType.Unknown, iox.ToString());
+ throw new TTransportException(TTransportException.ExceptionType.Unknown, iox.ToString(), iox);
}
}
@@ -217,11 +217,11 @@
}
catch (IOException iox)
{
- throw new TTransportException(TTransportException.ExceptionType.Unknown, iox.ToString());
+ throw new TTransportException(TTransportException.ExceptionType.Unknown, iox.ToString(), iox);
}
catch (WebException wx)
{
- throw new TTransportException(TTransportException.ExceptionType.Unknown, "Couldn't connect to server: " + wx);
+ throw new TTransportException(TTransportException.ExceptionType.Unknown, "Couldn't connect to server: " + wx, wx);
}
}
@@ -316,7 +316,7 @@
}
catch (IOException iox)
{
- throw new TTransportException(iox.ToString());
+ throw new TTransportException(iox.ToString(), iox);
}
}
@@ -360,7 +360,7 @@
}
catch (Exception exception)
{
- flushAsyncResult.AsyncException = new TTransportException(exception.ToString());
+ flushAsyncResult.AsyncException = new TTransportException(exception.ToString(), exception);
flushAsyncResult.UpdateStatusToComplete();
flushAsyncResult.NotifyCallbackWhenAvailable();
}
@@ -375,7 +375,7 @@
}
catch (Exception exception)
{
- flushAsyncResult.AsyncException = new TTransportException(exception.ToString());
+ flushAsyncResult.AsyncException = new TTransportException(exception.ToString(), exception);
}
flushAsyncResult.UpdateStatusToComplete();
flushAsyncResult.NotifyCallbackWhenAvailable();
diff --git a/lib/csharp/src/Transport/TNamedPipeServerTransport.cs b/lib/csharp/src/Transport/TNamedPipeServerTransport.cs
index a6cfb2e..32215cf 100644
--- a/lib/csharp/src/Transport/TNamedPipeServerTransport.cs
+++ b/lib/csharp/src/Transport/TNamedPipeServerTransport.cs
@@ -130,7 +130,7 @@
if (stream != null)
eOuter = e;
else
- eOuter = new TTransportException(TTransportException.ExceptionType.Interrupted, e.Message);
+ eOuter = new TTransportException(TTransportException.ExceptionType.Interrupted, e.Message, e);
}
evt.Set();
}, null);
@@ -157,7 +157,7 @@
catch (Exception e)
{
Close();
- throw new TTransportException(TTransportException.ExceptionType.NotOpen, e.Message);
+ throw new TTransportException(TTransportException.ExceptionType.NotOpen, e.Message, e);
}
}
@@ -214,7 +214,7 @@
if (stream != null)
eOuter = e;
else
- eOuter = new TTransportException(TTransportException.ExceptionType.Interrupted, e.Message);
+ eOuter = new TTransportException(TTransportException.ExceptionType.Interrupted, e.Message, e);
}
evt.Set();
}, null);
@@ -265,7 +265,7 @@
if (stream != null)
eOuter = e;
else
- eOuter = new TTransportException(TTransportException.ExceptionType.Interrupted, e.Message);
+ eOuter = new TTransportException(TTransportException.ExceptionType.Interrupted, e.Message, e);
}
evt.Set();
}, null);
diff --git a/lib/csharp/src/Transport/TServerSocket.cs b/lib/csharp/src/Transport/TServerSocket.cs
index 40e47dc..d8ec62a 100644
--- a/lib/csharp/src/Transport/TServerSocket.cs
+++ b/lib/csharp/src/Transport/TServerSocket.cs
@@ -93,10 +93,10 @@
this.server = TSocketVersionizer.CreateTcpListener(this.port);
this.server.Server.NoDelay = true;
}
- catch (Exception)
+ catch (Exception ex)
{
server = null;
- throw new TTransportException("Could not create ServerSocket on port " + this.port + ".");
+ throw new TTransportException("Could not create ServerSocket on port " + this.port + ".", ex);
}
}
@@ -111,7 +111,7 @@
}
catch (SocketException sx)
{
- throw new TTransportException("Could not accept on listening socket: " + sx.Message);
+ throw new TTransportException("Could not accept on listening socket: " + sx.Message, sx);
}
}
}
@@ -153,7 +153,7 @@
}
catch (Exception ex)
{
- throw new TTransportException(ex.ToString());
+ throw new TTransportException(ex.ToString(), ex);
}
}
@@ -167,7 +167,7 @@
}
catch (Exception ex)
{
- throw new TTransportException("WARNING: Could not close server socket: " + ex);
+ throw new TTransportException("WARNING: Could not close server socket: " + ex, ex);
}
server = null;
}
diff --git a/lib/csharp/src/Transport/TTLSServerSocket.cs b/lib/csharp/src/Transport/TTLSServerSocket.cs
index aa8ff7c..716a97c 100644
--- a/lib/csharp/src/Transport/TTLSServerSocket.cs
+++ b/lib/csharp/src/Transport/TTLSServerSocket.cs
@@ -129,10 +129,10 @@
this.server = TSocketVersionizer.CreateTcpListener(this.port);
this.server.Server.NoDelay = true;
}
- catch (Exception)
+ catch (Exception ex)
{
server = null;
- throw new TTransportException("Could not create ServerSocket on port " + this.port + ".");
+ throw new TTransportException("Could not create ServerSocket on port " + this.port + ".", ex);
}
}
@@ -150,7 +150,7 @@
}
catch (SocketException sx)
{
- throw new TTransportException("Could not accept on listening socket: " + sx.Message);
+ throw new TTransportException("Could not accept on listening socket: " + sx.Message, sx);
}
}
}
@@ -197,7 +197,7 @@
}
catch (Exception ex)
{
- throw new TTransportException(ex.ToString());
+ throw new TTransportException(ex.ToString(), ex);
}
}
@@ -214,7 +214,7 @@
}
catch (Exception ex)
{
- throw new TTransportException("WARNING: Could not close server socket: " + ex);
+ throw new TTransportException("WARNING: Could not close server socket: " + ex, ex);
}
this.server = null;
}
diff --git a/lib/csharp/src/Transport/TTransportException.cs b/lib/csharp/src/Transport/TTransportException.cs
index ae987d5..7f6cc18 100644
--- a/lib/csharp/src/Transport/TTransportException.cs
+++ b/lib/csharp/src/Transport/TTransportException.cs
@@ -40,14 +40,14 @@
this.type = type;
}
- public TTransportException(ExceptionType type, string message)
- : base(message)
+ public TTransportException(ExceptionType type, string message, Exception inner = null)
+ : base(message, inner)
{
this.type = type;
}
- public TTransportException(string message)
- : base(message)
+ public TTransportException(string message, Exception inner = null)
+ : base(message, inner)
{
}