Item 73. Abstraction Level Exceptions
μμΈ λ²μ(exception translation)
class Example {
public static void main(String[] args) {
try {
// ...
} catch (LowerLevelException e) {
// μΆμν μμ€μ λ§κ² λ€λ₯Έ μμΈλ‘ μ ν
throw new HigherLevelException();
}
}
}public abstract class AbstractSequentialList<E> extends AbstractList<E> {
public E get(int index) {
try {
return listIterator(index).next();
} catch (NoSuchElementException exc) {
throw new IndexOutOfBoundsException("Index: " + index);
}
}
}μμΈ μ°μ(exception chaining)
Last updated