Trying to simplify exception message but it's not being caught

Viewed 29

I'm attempting to shorten an exception that is being output to a log file. The exception is occurring but the contains is working how I intended it.

This is the message:

!Dropbox Success Message: System.AggregateException: One or more errors occurred. ---> System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel. at System.Net.HttpWebRequest.EndGetRequestStream(IAsyncResult asyncResult, TransportContext& context) at System.Net.Http.HttpClientHandler.GetRequestStreamCallback(IAsyncResult ar) --- End of inner exception stack trace --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at Dropbox.Api.DropboxRequestHandler.d__18.MoveNext() --- End of stack trace from previous location where exception was thrown ---

This is what I'm trying to do:

  catch (Exception e)
  {
    if (e.ToString().Contains("Could not create SSL/TLS secure channel"))
    {
      _report.Add($"!Exception occurred in SendToDropbox.");
      _report.Add($"!Could not create SSL/TLS secure channel.");
    }
    else
    {
      _report.Add($"!Exception occurred in SendToDropbox.");
      _report.Add($"!{e}");
    }

The .contains isn't catching the message in the exception. The odd thing is, the exception is being output with that phrase in it so I don't understand why the contains wouldn't catch it.

Why isn't the contains catching it? What am I doing wrong?

0 Answers
Related