[btls] Capture inner exception in MobileAuthenticatedStream
authorAlexander Köplinger <alex.koeplinger@outlook.com>
Mon, 9 Jan 2017 18:48:37 +0000 (19:48 +0100)
committerAlexander Köplinger <alex.koeplinger@outlook.com>
Mon, 9 Jan 2017 18:48:37 +0000 (19:48 +0100)
Previously we'd just throw the catched exception again
which overwrites its stacktrace, making it less useful
since all you can see is e.g. a NullReferenceException
(re)thrown at MobileAuthenticatedStream:218.

We now capture the original exception information so
the stacktrace is more complete.

mcs/class/System/Mono.Net.Security/MobileAuthenticatedStream.cs

index cf1082618e625432d5df952fbbe10d769f8591b5..8ca8fb6575455eefcd1ce6e67d3adb46d0e75b8c 100644 (file)
@@ -23,6 +23,7 @@ using System.IO;
 using System.Net;
 using System.Net.Security;
 using System.Globalization;
 using System.Net;
 using System.Net.Security;
 using System.Globalization;
+using System.Runtime.ExceptionServices;
 using System.Threading;
 using System.Threading.Tasks;
 using System.Security.Cryptography.X509Certificates;
 using System.Threading;
 using System.Threading.Tasks;
 using System.Security.Cryptography.X509Certificates;
@@ -214,7 +215,7 @@ namespace Mono.Net.Security
                                try {
                                        asyncRequest.StartOperation (ProcessHandshake);
                                } catch (Exception ex) {
                                try {
                                        asyncRequest.StartOperation (ProcessHandshake);
                                } catch (Exception ex) {
-                                       throw SetException (ex);
+                                       ExceptionDispatchInfo.Capture (SetException (ex)).Throw ();
                                }
                        } finally {
                                if (lazyResult == null || lastException != null) {
                                }
                        } finally {
                                if (lazyResult == null || lastException != null) {
@@ -241,7 +242,7 @@ namespace Mono.Net.Security
 
                        var e = lazyResult.Result as Exception;
                        if (e != null)
 
                        var e = lazyResult.Result as Exception;
                        if (e != null)
-                               throw SetException (e);
+                               ExceptionDispatchInfo.Capture (SetException (e)).Throw ();
                }
 
                internal void ValidateCreateContext (bool serverMode, string targetHost, SslProtocols enabledProtocols, X509Certificate serverCertificate, X509CertificateCollection clientCertificates, bool clientCertRequired)
                }
 
                internal void ValidateCreateContext (bool serverMode, string targetHost, SslProtocols enabledProtocols, X509Certificate serverCertificate, X509CertificateCollection clientCertificates, bool clientCertRequired)