来自扩展 java.beans.PropertyEditorSupport 的类:
/**
* Sets the property value by parsing a given String. May raise
* java.lang.IllegalArgumentException if either the String is
* badly formatted or if this kind of property can't be expressed
* as text.
*
* @param text The string to be parsed.
*/
public void setAsText(String name) {
try {
asEnum(name);
} catch (InvalidEnumNameException e) {
throw new IllegalArgumentException("Unable to convert value: "+ name);
}
}
将导致真实的堆栈跟踪丢失。
最佳答案
IllegalArgumentException does have constructors带有 Throwable
cause
参数 - 该代码根本不使用它们,可能是因为它比“异常有一个 Throwable
cause
”约定,该约定是随 Java 5 引入的。
关于java - 为什么 IllegalArgumentException (JDK 1.4.2) 不能用可抛出的原因构造?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1476238/