title: Recommended method for handling UnsupportedEncodingException from String.getBytes("UTF-8")
body: <p>What is the recommended way to handle an <a href="http://docs.oracle.com/javase/6/docs/api/java/io/UnsupportedEncodingException.html" rel="noreferrer">UnsupportedEncodingException </a> when calling String.getBytes("UTF-8") inside a library method? </p>
  
  <p>If I'm reading <a href="http://docs.oracle.com/javase/6/docs/technotes/guides/intl/encoding.doc.html" rel="noreferrer">http://docs.oracle.com/javase/6/docs/technotes/guides/intl/encoding.doc.html</a> correctly, UTF-8 encoding should <em>always</em> be available, which leads me to believe there's no reason to pass this exception on to the library's consumer (that is, add a <code>throws</code> clause to the method signature). It seems any failure mode that made UTF-8 encoding facilities unavailable would be catastrophic, leading me to write this handler:</p>
  
  <pre><code>    try
      {
          ....
          return "blah".getBytes("UTF-8");
      }
      catch (UnsupportedEncodingException e)
      {
          // we're assuming UTF-8 encoding is always available.
          // see
          // http://docs.oracle.com/javase/6/docs/technotes/guides/intl/encoding.doc.html
          e.printStackTrace();
          return null; //prevent compile-time "method must return a result" errors
      }
  </code></pre>
  
  <p>Is there a failure mode that wouldn't be addressed by this snippet?</p>