title: Ternary operator for exceptions? Other alternatives?
body: <p>Assuming we have a given object of type Person and want to store its Name property in to a local variable while avoiding possible exceptions should the object be null, we can do this:</p>
  
  <pre><code>string personName = null;
  
  if (person != null)
  {
      personName = person.Name;
  }
  </code></pre>
  
  <p>However, having to declare the variable outside the scope of the if statement and initialize it to a default value is a bit cumbersome. Instead, we can write it like this using the conditional ternary operator:</p>
  
  <pre><code>string personName = person != null ? person.Name : null;
  </code></pre>
  
  <p>This same sort of problem exists when dealing with try-catch statements. Let's say we were trying to find the remote address of a TcpClient. We may do something like this:</p>
  
  <pre><code>string remoteAddress = null;
  
  try
  {
      remoteAddress = tcpClient.Client.RemoteEndPoint.ToString();
  }
  catch (SocketException e)
  {
      Console.WriteLine(e.Message);
  
      return;
  }
  </code></pre>
  
  <p>However, as far as I can tell, there is no operator defined for simplifying such a thing, and I suppose for good reason, considering the possible complexity. I wonder though, is there a way to make this sort of thing more concise? Perhaps a solution involving monads would work or maybe this code should be left as it is.</p>