User: jung
Date: 01/01/04 06:45:04
Modified: src/de/infor/ce/console ConsoleException.java
Log:
exception redesign. Improved null-pointer treatment. coherent environment and
logging facilities.
LGPL references.
Revision Changes Path
1.3 +58 -36 zoap/src/de/infor/ce/console/ConsoleException.java
Index: ConsoleException.java
===================================================================
RCS file: /products/cvs/ejboss/zoap/src/de/infor/ce/console/ConsoleException.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ConsoleException.java 2000/12/22 15:43:20 1.2
+++ ConsoleException.java 2001/01/04 14:45:04 1.3
@@ -26,53 +26,75 @@
* went wrong. We do not want to produce any exception upon failures
* inside the logging - that could easily cause recursive trouble!
* @author jung
- * @version $Revision: 1.2 $
+ * @version $Revision: 1.3 $
*/
public class ConsoleException extends Exception {
- /** an embedded exception */
- Throwable actualThrowable;
+ /** nested exception */
+ protected Throwable detail;
- /** constructor for embedding an arbitrary throwable */
- public ConsoleException(Throwable throwable) {
- super();
- actualThrowable = throwable;
- }
-
- /** message-based constructor for embedding an arbitrary throwable */
- public ConsoleException(String message, Throwable throwable) {
- super(message);
- actualThrowable = throwable;
- }
+ /** constructs a barebone <code>ConsoleException</code> */
+ public ConsoleException() { }
- public ConsoleException(String message) {
- super(message);
+ /** Constructs a <code>ConsoleException</code> with the specified error
message. */
+ public ConsoleException(String s) {
+ super(s);
}
- /** default constructor */
- public ConsoleException() {
+ /** constructs a <code>ConsoleException</code> with the specified detail
message and a nested throwable. */
+ public ConsoleException(String s, Throwable ex) {
+ super(s);
+ detail = ex;
}
- /** accesses the embedded throwable */
- public Throwable getActualThrowable() {
- return actualThrowable;
- }
-
- /** accesses the embedded throwable */
- public void setActualThrowable(Throwable throwable) {
- actualThrowable = throwable;
+ /** constructs a <code>ConsoleException</code> with a nested throwable. */
+ public ConsoleException(Throwable ex) {
+ super();
+ detail = ex;
}
- /** manipulate the toString method to also show the embedded throwable */
- public String toString() {
- return super.toString() + ": embedded exception " +
actualThrowable.toString();
+ /** returns the detail exception */
+ public Throwable getDetail() {
+ return detail;
+ }
+
+ /** returns the detail message, including the message from the nested
exception if there is one. */
+ public String getMessage() {
+ if (detail == null)
+ return super.getMessage();
+ else
+ return super.getMessage() +
+ "; nested exception is: \n\t" +
+ detail.toString();
+ }
+
+ /**
+ * prints the composite message and the embedded stack trace to the specified
stream <code>ps</code>.
+ * @param ps the print stream
+ */
+ public void printStackTrace(java.io.PrintStream ps) {
+ synchronized(ps) {
+ super.printStackTrace(ps);
+ if (detail != null) {
+ ps.println("\t nested exception trace is:");
+ detail.printStackTrace(ps);
+ }
+ }
+ }
+
+ /**
+ * Prints the composite message and the embedded stack trace to the specified
print writer <code>pw</code>.
+ * @param pw the print writer
+ */
+ public void printStackTrace(java.io.PrintWriter pw) {
+ synchronized(pw) {
+ super.printStackTrace(pw);
+ if (detail != null) {
+ pw.println("\t nested exception trace is:");
+ detail.printStackTrace(pw);
+ }
+ }
}
- /** the printStackTrace method produces recursive traces */
- public void printStackTrace() {
- super.printStackTrace();
- if (actualThrowable != null)
- actualThrowable.printStackTrace();
- }
}