Web design tools - original exception thrown may be IOExceptionor SQLException, but
original exception thrown may be IOExceptionor SQLException, but the user doesn’t need to know or care about this level of detail; all he needs to know is that the update function failed. Although the end user doesn’t care about the specific exception thrown, the system administrator or the developers who will be assigned the task of debugging and fixing the problem do. That’s why you don’t want to throw away the root cause of the problem when you rethrow a different exception. Prior to Version 1.4, Java didn’t provide a built-in mechanism to wrap the original exception with a new one. Developers were left to their own devices to solve the problem. Most homegrown solutions looked something like the exception class in Example 10-1. Example 10-1. An exception class that supports chained exceptions import java.io.PrintStream; import java.io.PrintWriter; /** * This is the common superclass for all applicationexceptions. This * class and its subclasses support the chained exceptionfacility that allows * a root cause Throwable to be wrapped by this class or oneof its * descendants. */ public class BaseException extends Exception { protected Throwable rootCause = null; protected BaseException( Throwable rootCause ) { this.rootCause = rootCause; } public void setRootCause(Throwable anException) { rootCause = anException; } public Throwable getRootCause( ) { return rootCause; } public void printStackTrace( ) { printStackTrace(System.err); } public void printStackTrace(PrintStream outStream) { printStackTrace(new PrintWriter(outStream)); } public void printStackTrace(PrintWriter writer) { super.printStackTrace(writer); if ( getRootCause( ) != null ) {
Searching for affordable and proven webhost to host and run your servlet applications? Go to Linux Web Hosting services and you will find it.