NESTING AN EXCEPTION What should you do if you are catching an Exception and want to throw a new one, but you still want the original Exception's information to be available? Try creating a NestedException class. This is easy to do and the only major issues to deal with are providing enough constructors and overriding printStackTrace() so it prints out data properly. You should also consider wrapping a Throwable and not just an Exception to create a more reusable component and then creating a NestedRuntimeException variant that can wrap a Throwable, but not need to be declared. package com.generationjava.lang; import java.io.PrintStream; import java.io.PrintWriter; /** * An Exception which is being thrown on top of another * Throwable. That is, some code has caught an Exception * and wishes to throw a different Exception upwards * as a result. This class allows the original Exception * to still be accessible. * * @author bayard@generationjava.com */ public class NestedException extends Exception { private Throwable wrappedThrowable; public NestedException(String s) { super(s); } public NestedException() { super(); } public NestedException(String s, Throwable t) { super(s); setWrappedThrowable(t); } public NestedException(Throwable t) { super(); setWrappedThrowable(t); } /** * Access the original exception. * * @return Throwable that was initially throw */ public Throwable getWrappedThrowable() { return wrappedThrowable; } /** * Reset the original exception. * * @param t Throwable to be wrapped */ public void setWrappedThrowable(Throwable t) { wrappedThrowable = t; } public void printStackTrace() { super.printStackTrace(); if(wrappedThrowable != null) { System.err.println("Nested Exception: "); wrappedThrowable.printStackTrace(); } } public void printStackTrace(PrintStream ps) { super.printStackTrace(ps); if(wrappedThrowable != null) { ps.println("Nested Exception: "); wrappedThrowable.printStackTrace(ps); } } public void printStackTrace(PrintWriter pw) { super.printStackTrace(pw); if(wrappedThrowable != null) { pw.println("Nested Exception: "); wrappedThrowable.printStackTrace(pw); } } } ----------------------------------------