[cvs] expresso commit by rimovm: NonHandleableException is now a runtime

JCorporate Ltd jcorp at jcorporate.com
Sat May 7 06:44:29 UTC 2005


Log Message:
-----------
NonHandleableException is now a runtime exception and therefore OPTIONAL in method signatures (and Handling)!

Modified Files:
--------------
    expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/controller:
        NonHandleableException.java

Added Files:
-----------
    expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/kernel/exception:
        ChainedRuntimeException.java

Revision Data
-------------
Index: NonHandleableException.java
===================================================================
RCS file: /home/javacorp/.cvs/expresso/expresso/expresso-web/WEB-INF/src/com/jcorporate/expresso/core/controller/NonHandleableException.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -Lexpresso-web/WEB-INF/src/com/jcorporate/expresso/core/controller/NonHandleableException.java -Lexpresso-web/WEB-INF/src/com/jcorporate/expresso/core/controller/NonHandleableException.java -u -r1.7 -r1.8
--- expresso-web/WEB-INF/src/com/jcorporate/expresso/core/controller/NonHandleableException.java
+++ expresso-web/WEB-INF/src/com/jcorporate/expresso/core/controller/NonHandleableException.java
@@ -70,7 +70,7 @@
  * Copyright 1999, 2000, 2001 Jcorporate Ltd.
  */
 
-import com.jcorporate.expresso.kernel.exception.ChainedException;
+import com.jcorporate.expresso.kernel.exception.ChainedRuntimeException;
 
 
 /**
@@ -79,12 +79,12 @@
  * has an error itself, or ControllerServlet has an error while trying to call it,
  * we can't just call ErrorHandler to deal with it :-), so we throw
  * this Exception to indicate that ErrorHandler should not be called.
- *
+ * <p><strong>Since Expresso 5.7 This has been changed to a type of a <em>Runtime
+ * Exception</em> to provide for its eventual phaseout</strong></p>
  * @author Michael Nash
  * @version $Revision$  $Date$
  */
-public class NonHandleableException
-        extends ChainedException {
+public class NonHandleableException extends ChainedRuntimeException {
     /**
      * Constructor
      */
@@ -122,4 +122,4 @@
 
 } /* NonHandleableException */
 
-/* NonHandleableException */
\ No newline at end of file
+/* NonHandleableException */
--- /dev/null
+++ expresso-web/WEB-INF/src/com/jcorporate/expresso/kernel/exception/ChainedRuntimeException.java
@@ -0,0 +1,191 @@
+package com.jcorporate.expresso.kernel.exception;
+
+import java.io.PrintWriter;
+import java.io.PrintStream;
+
+/**
+ * Runtime Exception that chains exceptions.  This will not be needed after
+ * people have completly migrated to JDK 1.4 and above since RuntimeException
+ * automatically has nested Exception constructors at that point.  But until
+ * then, this class is needed.
+ * @author Michael Rimov
+ * @version $Revision: 1.1 $ on $Date: 2005/05/07 06:44:26 $
+ */
+public class ChainedRuntimeException extends RuntimeException
+{
+    /**
+     * The nested Exception
+     */
+    private Throwable nested = null;
+
+    /**
+     * The error number.
+     */
+    private int errorNumber = 0;
+
+    /**
+     * Normal no-args constructor
+     */
+    public ChainedRuntimeException() {
+        super();
+    }
+    /* ChaninedException() */
+
+    /**
+     * Normal constructor with a single message
+     *
+     * @param s The exception message
+     */
+    public ChainedRuntimeException(String s) {
+        super(s);
+    }
+    /* Chained Exception */
+
+    /**
+     * Specify an error number
+     *
+     * @param s              the message
+     * @param newErrorNumber The error number to assign
+     */
+    public ChainedRuntimeException(String s, int newErrorNumber) {
+        super(s);
+        errorNumber = newErrorNumber;
+    }
+
+    /**
+     * Constructor with a single message and a nested exception
+     *
+     * @param message   The exception message
+     * @param newNested The nested item
+     */
+    public ChainedRuntimeException(String message, Throwable newNested) {
+        super(message);
+        nested = newNested;
+    }
+    /* ChainedException(String, Throwable) */
+
+    /**
+     * Constructor with a single message and a nested exception with error number
+     *
+     * @param message        The exception message
+     * @param newNested      The nested item
+     * @param newErrorNumber the error number associated with the exception
+     */
+    public ChainedRuntimeException(String message, Throwable newNested,
+        int newErrorNumber) {
+        super(message);
+        nested = newNested;
+        errorNumber = newErrorNumber;
+    }
+    /* ChainedException(String, Throwable) */
+
+    /**
+     * Constructor with no message and a nested exception
+     *
+     * @param newNested The nested exception
+     */
+    public ChainedRuntimeException(Throwable newNested) {
+        nested = newNested;
+    }
+    /* ChainedException(Throwable) */
+
+    /**
+     * Constructor with no message and a nested exception, but with an error number
+     *
+     * @param newNested      The nested exception
+     * @param newErrorNumber the error number associated with the exception message
+     */
+    public ChainedRuntimeException(Throwable newNested, int newErrorNumber) {
+        nested = newNested;
+        errorNumber = newErrorNumber;
+    }
+    /* ChainedException(Throwable) */
+
+    /**
+     * Extend getMessage to return the nested message (if any) if we don't have one
+     *
+     * @return java.lang.String
+     */
+    public String getMessage() {
+        String myMessage = super.getMessage();
+
+        if ((myMessage == null) && (nested != null)) {
+            myMessage = ("Nested exception: " + omitPackages(nested) + ": " +
+                nested.getMessage());
+        }
+
+        return myMessage;
+    }
+    /* getMessage() */
+
+    /**
+     * utility to get just name of class
+     *
+     * @param obj the object of the given class, the name of which will be returned
+     * @return name of class, less any package prefix
+     */
+    public static String omitPackages(Object obj) {
+        int i = obj.getClass().getPackage().getName().length();
+        if (i > 0) {
+            i++;
+        }
+        return obj.getClass().getName().substring(i);
+    }
+
+    /**
+     * Return the error number if one was supplied
+     *
+     * @return integer: the error number specified (or zero if non was specified)
+     */
+    public int getErrorNumber() {
+        return errorNumber;
+    }
+
+    /**
+     * Extend printStackTrace to handle the nested exception correctly.
+     */
+    public void printStackTrace() {
+        if (nested != null) {
+            nested.printStackTrace();
+        }
+        super.printStackTrace();
+    }
+    /* printStackTrace() */
+
+    /**
+     * Extend printStackTrace to handle the nested Exception
+     *
+     * @param p The PrintStream to write the exception messages into
+     */
+    public void printStackTrace(PrintStream p) {
+        if (nested != null) {
+            nested.printStackTrace(p);
+        }
+        super.printStackTrace(p);
+
+    }
+    /* printStackTrace(PrintStream) */
+
+    /**
+     * Extend printStackTrace to handle the nested Exception
+     *
+     * @param p The PrintWriter to write the exception messages into
+     */
+    public void printStackTrace(PrintWriter p) {
+        if (nested != null) {
+            nested.printStackTrace(p);
+        }
+        super.printStackTrace(p);
+    }
+    /* printStackTrace(PrintWriter) */
+
+    /**
+     * Retrieve the nested exception
+     *
+     * @return the nested Exception
+     */
+    public Throwable getNested() {
+        return nested;
+    }
+    /* getNested() */
+}


More information about the cvs mailing list