我一直很好奇如何抛出
java.lang.InternalError或
java.lang.UnknownError.
我的意思并不简单
throw new InternalError();
throw new UnknownError();
但是Java SE库或JVM本身抛出了一个(最近通常的Oracle实现).
例如,使ArrayList.clone真正抛出InternalError的特定代码或环境是我想要的答案.以下是其源代码.
public Object clone() {
try {
ArrayList> v = (ArrayList>) super.clone();
v.elementData = Arrays.copyOf(elementData, size);
v.modCount = 0;
return v;
} catch (CloneNotSupportedException e) {
// this shouldn't happen, since we are Cloneable
throw new InternalError(e);
}
}