title: Best practice to look up Java Enum
body: <p>We have a REST API where clients can supply parameters representing values defined on the server in Java Enums.</p>
  
  <p>So we can provide a descriptive error, we add this <code>lookup</code> method to each Enum.  Seems like we're just copying code (bad).  Is there a better practice?  </p>
  
  <pre><code>public enum MyEnum {
      A, B, C, D;
  
      public static MyEnum lookup(String id) {
          try {
              return MyEnum.valueOf(id);
          } catch (IllegalArgumentException e) {
              throw new RuntimeException("Invalid value for my enum blah blah: " + id);
          }
      }
  }
  </code></pre>
  
  <p><strong>Update</strong>: The default error message provided by <code>valueOf(..)</code> would be <code>No enum const class a.b.c.MyEnum.BadValue</code>.  I would like to provide a more descriptive error from the API.  </p>