summaryrefslogtreecommitdiffstats
path: root/base/common/src
diff options
context:
space:
mode:
authorEndi S. Dewata <edewata@redhat.com>2015-01-20 09:25:32 -0500
committerEndi S. Dewata <edewata@redhat.com>2015-01-21 15:35:37 -0500
commit802f7471d5ee65e3c4d99b528bb6d8526c277185 (patch)
tree02dd03d41e301499b0b28fbd0af948f253bac03d /base/common/src
parentdeb188bffd38f82396c47411381a875020ca748b (diff)
downloadpki-802f7471d5ee65e3c4d99b528bb6d8526c277185.tar.gz
pki-802f7471d5ee65e3c4d99b528bb6d8526c277185.tar.xz
pki-802f7471d5ee65e3c4d99b528bb6d8526c277185.zip
Added support for exception chains in EBaseException.
The EBaseException has been modified to provide constructors that can be used to chain the cause of the exception. This way the root cause of the exception can be traced back to help troubleshooting. Some codes have been modified to utilize the proper exception chaining as examples. https://fedorahosted.org/pki/ticket/915
Diffstat (limited to 'base/common/src')
-rw-r--r--base/common/src/com/netscape/certsrv/apps/CMS.java14
-rw-r--r--base/common/src/com/netscape/certsrv/base/EBaseException.java60
2 files changed, 51 insertions, 23 deletions
diff --git a/base/common/src/com/netscape/certsrv/apps/CMS.java b/base/common/src/com/netscape/certsrv/apps/CMS.java
index 63c1a2cbd..8b4bac2c0 100644
--- a/base/common/src/com/netscape/certsrv/apps/CMS.java
+++ b/base/common/src/com/netscape/certsrv/apps/CMS.java
@@ -17,8 +17,6 @@
// --- END COPYRIGHT BLOCK ---
package com.netscape.certsrv.apps;
-import java.io.ByteArrayOutputStream;
-import java.io.PrintStream;
import java.math.BigInteger;
import java.security.NoSuchAlgorithmException;
import java.security.cert.Certificate;
@@ -1586,21 +1584,19 @@ public final class CMS {
CMS.startup();
} catch (EBaseException e) { // catch everything here purposely
- CMS.debug("CMS:Caught EBaseException");
CMS.debug(e);
// Raidzilla Bug #57592: Always print error message to stdout.
- System.out.println(e.toString());
+ System.out.println(e);
shutdown();
throw e;
- } catch (Exception e) { // catch everything here purposely
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- PrintStream ps = new PrintStream(bos);
- e.printStackTrace(ps);
+ } catch (Exception e) { // catch everything here purposely
+ CMS.debug(e);
System.out.println(Constants.SERVER_SHUTDOWN_MESSAGE);
- throw new EBaseException(bos.toString());
+
+ throw new EBaseException(e);
// cms.shutdown();
}
}
diff --git a/base/common/src/com/netscape/certsrv/base/EBaseException.java b/base/common/src/com/netscape/certsrv/base/EBaseException.java
index 140a6acbc..78d9a6d2d 100644
--- a/base/common/src/com/netscape/certsrv/base/EBaseException.java
+++ b/base/common/src/com/netscape/certsrv/base/EBaseException.java
@@ -63,25 +63,24 @@ public class EBaseException extends Exception {
}
/**
- * Constructs an instance of the exception given the resource key and
- * a exception parameter.
+ * Constructs an instance of this exception given the resource key and
+ * the cause exception.
*
- * <PRE>
- * try {
- * ...
- * } catch (IOExeption e) {
- * throw new EBaseException(BaseResources.INTERNAL_ERROR_1, e);
- * }
- * </PRE>
- * <P>
+ * <pre>
+ * try {
+ * ...
+ * } catch (IOExeption e) {
+ * throw new EBaseException(BaseResources.INTERNAL_ERROR_1, e);
+ * }
+ * </pre>
*
* @param msgFormat The resource key
- * @param param The parameter as an exception
+ * @param cause The cause exception
*/
- public EBaseException(String msgFormat, Exception param) {
- super(msgFormat);
+ public EBaseException(String msgFormat, Exception cause) {
+ super(msgFormat, cause);
mParams = new Exception[1];
- mParams[0] = param;
+ mParams[0] = cause;
}
/**
@@ -98,6 +97,39 @@ public class EBaseException extends Exception {
}
/**
+ * Constructs an instance of this exception given the resource key,
+ * an array of parameters, and the cause exception.
+ * <P>
+ *
+ * @param msgFormat The resource key
+ * @param params Array of params
+ * @param cause The cause exception
+ */
+ public EBaseException(String msgFormat, Object params[], Exception cause) {
+ super(msgFormat, cause);
+ mParams = params;
+ }
+
+ /**
+ * Constructs an instance of this exception given the cause exception.
+ *
+ * <pre>
+ * try {
+ * ...
+ * } catch (IOExeption e) {
+ * throw new EBaseException(e);
+ * }
+ * </pre>
+ *
+ * @param cause The cause exception
+ */
+ public EBaseException(Exception cause) {
+ super(cause.getMessage() == null ? cause.getClass().getName() : cause.getMessage(), cause);
+ mParams = new Exception[1];
+ mParams[0] = cause;
+ }
+
+ /**
* Returns the list of parameters.
* <P>
*