2

I am getting a NumberFormatException and i want to fetch the value from the exception itself , which looks like
enter image description here

But there is no getter available for the value, can anyone suggest any solution to fetch this value rather than reflection, or even reflection can be fine.

Joshua
  • 40,822
  • 8
  • 72
  • 132
Anand Kadhi
  • 1,790
  • 4
  • 27
  • 40

2 Answers2

4

If you explicitly check for TypeMismatchException, you can retrieve that value simply by calling getValue()

http://docs.spring.io/spring-framework/docs/2.0.8/api/org/springframework/beans/TypeMismatchException.html#getValue()

Jan
  • 13,738
  • 3
  • 30
  • 55
2

You could get value from org.springframework.beans.TypeMismatchException just use Object getValue(), for example, using following code:

...
} catch(Exception exception) {
   if(exception instanceof TypeMismatchException) {
      Object value = ((TypeMismatchException) exp).getValue;
      ... // what you want to do with value
   }
}

or just

...
} catch(TypeMismatchException exception) {
      Object value = exp.getValue;
      ... // what you want to do with value
}

Because org.springframework.beans.TypeMismatchException define as

package org.springframework.beans;
public class TypeMismatchException extends PropertyAccessException {
...
    /**
     * Return the offending value (may be {@code null})
     */
    @Override
    public Object getValue() {
        return this.value;
    }
...
}
Slava Vedenin
  • 58,326
  • 13
  • 40
  • 59