在运行时检查异常是否为已检查异常
Check if an exception is a checked exception at runtime
这是在运行时检查异常是否为已检查异常的正确方法吗?
public boolean isChecked(final Throwable e) {
return !(RuntimeException.class.isAssignableFrom(e.getClass())
|| Error.class.isAssignableFrom(e.getClass()));
}
我想像下面这样的一些条件就足够了
return !(e instanceof RuntimeException || e instanceof Error);
这是在运行时检查异常是否为已检查异常的正确方法吗?
public boolean isChecked(final Throwable e) {
return !(RuntimeException.class.isAssignableFrom(e.getClass())
|| Error.class.isAssignableFrom(e.getClass()));
}
我想像下面这样的一些条件就足够了
return !(e instanceof RuntimeException || e instanceof Error);