[sample] Exception Chaining
package JDK14Tutorial.chapter7;
/**
* 이 예제는 Manning사의 JSK 1.4 Tutorial에 있는 소스를 테스트하는 것이다.
*
* JDK 1.4에서 추가된 Throwable 객체의
* 생성자인 Throwable(String message, Throwable cause) 와
* getCause() 함수를 테스트하는 목적이다.
*
* @author seveny
* @date 2003.02.07 금요일
*
*/
public class TraverseExceptionChain {
/**
* Method traverseExceptionChain.
* 익셉션 체인을 따라가면서 각 익셉션을 출력한다.
*
* @param t 익셉션 체인의 시작점
*/
static public void traverseExceptionChain(Throwable t) {
while (t != null) {
System.out.println(t);
t = t.getCause();
}
}
public static void main(String[] args) {
int array[] = new int[10];
try {
array[500] = 1;
} catch (Exception e) {
Exception e2 = new Exception("Two", e);
Exception e3 = new Exception("Three", e2);
traverseExceptionChain(e3);
}
}
}