从扩展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);
    }
}


会导致真正的堆栈跟踪丢失。

最佳答案

带有Throwable cause参数的IllegalArgumentException does have constructors-该代码根本不使用它们,可能是因为它早于Java 5引入的“ Exceptions are Throwable cause”约定。 。

关于java - 为什么不能使用可抛出的原因构造IllegalArgumentException(JDK 1.4.2)?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1476238/

10-09 06:55
查看更多