title: (How) is it possible to catch an exception in a Java ternary operator statement?
body: <p>I'm reformatting some legacy code that I don't fully understand, and in it there are several variable assignments that conditionally assign variables to the output of one of two formatting functions, using exception catching like so:</p>
  
  <pre><code>String myString;
  try {
      myString= foo(x);
  } catch (Exception e) {
      myString= bar(x);
  }
  </code></pre>
  
  <p>This seems like an abuse of exception handling, and anyway it's a lot of repeated boilerplate code for a lot of variable assignments.  Without digging into <code>foo</code> to identify the conditions that might cause exceptions, can I simplify this using a ternary operator expression?  I.e. something like this:</p>
  
  <pre><code>String myString = foo(x) ? foo(x) : bar(x)
  </code></pre>
  
  <p>but catching the exception that might be thrown by <code>foo(x)</code>.  Is there a way to do this in this one-liner?  Or if not, is there a better one-line expression that chooses between two assignments based on a possible exception?  I am using Java 8.</p>