java 异常

参数为空,抛这个异常IllegalArgumentException

public static void notNull(Object object, String message) {
if (object == null) {
throw new IllegalArgumentException(message);
}
}

状态异常,一般参数为false,或者converter instanceof ConditionalConverter为false,

参数不满足条件的时候就跑出IllegalStateException异常

public void add(Iterator<E> iterator) {
Assert.state(!this.inUse, "You can no longer add iterators to a composite iterator that's already in use");
if (this.iterators.contains(iterator)) {
throw new IllegalArgumentException("You cannot add the same iterator twice");
}
this.iterators.add(iterator);
}

public void add(GenericConverter converter) {
Set<ConvertiblePair> convertibleTypes = converter.getConvertibleTypes();
if (convertibleTypes == null) {
Assert.state(converter instanceof ConditionalConverter,
"Only conditional converters may return null convertible types");
this.globalConverters.add(converter);
}
else {
for (ConvertiblePair convertiblePair : convertibleTypes) {
ConvertersForPair convertersForPair = getMatchableConverters(convertiblePair);
convertersForPair.add(converter);
}
}
}

public int compare(T o1, T o2) {
Assert.state(this.comparators.size() > 0,
"No sort definitions have been added to this CompoundComparator to compare");
for (InvertibleComparator comparator : this.comparators) {
int result = comparator.compare(o1, o2);
if (result != 0) {
return result;
}
}
return 0;
}

原文地址:https://www.cnblogs.com/handsome1013/p/7249277.html