title: How to Catch/Handle Type Binding Errors in Spring MVC
body: <p>Suppose my form fields map to an Integer, Short, etc., and the input is invalid (non-numeric).</p>
  
  <p>I get the following in my errors map upon form submission:</p>
  
  <pre><code>Failed to convert property value of type 'java.lang.String' to required type 'java.lang.Short' for property 'property'; nested exception is java.lang.NumberFormatException: For input string: "a" 
  </code></pre>
  
  <p>I need to show a custom, user-friendly message. This doesn't work for me, it never comes here:</p>
  
  <pre><code>@ExceptionHandler(NumberFormatException.class)
  public String handleNumberConversion(NumberFormatException nfe)
  {
      return "error.invalidNumberFormat";
  }  
  </code></pre>
  
  <p>BindException doesn't work either - in fact even a generic Exception in the method signature won't get activated.</p>
  
  <p>EDIT: 2nd Attempt: I even tried this, this doesn't work either in my Resource Bundle, either:</p>
  
  <pre><code># SpringMVC Error Overrides
  typeMismatch.java.lang.NumberFormatException=A NumberFormatException occurred.
  typeMismatch.java.lang.Short={0} is an invalid value.
  typeMismatch.java.lang.Integer={0} is an invalid value.
  </code></pre>
  
  <p><strong>Also</strong>, I need to get some details from the Binding process exception, such as the field that was being bound and the current value, because my custom error message shows this information.</p>