diff --git a/cdap-api-common/src/main/java/io/cdap/cdap/api/exception/ProgramFailureException.java b/cdap-api-common/src/main/java/io/cdap/cdap/api/exception/ProgramFailureException.java
index 2cb2fb64f11..e8b30332327 100644
--- a/cdap-api-common/src/main/java/io/cdap/cdap/api/exception/ProgramFailureException.java
+++ b/cdap-api-common/src/main/java/io/cdap/cdap/api/exception/ProgramFailureException.java
@@ -32,19 +32,20 @@
*
errorReason: A reason for why the error occurred.
* errorType: The type of error, represented by the {@ErrorType} enum,
* such as SYSTEM, USER, or UNKNOWN.
+ * cause: The cause of this throwable or null if the cause is nonexistent
+ * or unknown.
*
**/
public class ProgramFailureException extends RuntimeException {
private final String errorCategory;
- private final String errorMessage;
private final String errorReason;
private final ErrorType errorType;
// Private constructor to prevent direct instantiation
private ProgramFailureException(String errorCategory, String errorMessage, String errorReason,
- ErrorType errorType) {
+ ErrorType errorType, Throwable cause) {
+ super(errorMessage, cause);
this.errorCategory = errorCategory;
- this.errorMessage = errorMessage;
this.errorReason = errorReason;
this.errorType = errorType;
}
@@ -62,15 +63,6 @@ public String getErrorCategory() {
return errorCategory == null ? "Others" : errorCategory;
}
- /**
- * Returns the detailed message associated with the error.
- *
- * @return a {@String} representing the error message.
- */
- public String getErrorMessage() {
- return errorMessage;
- }
-
/**
* Returns the reason for the error.
*
@@ -103,6 +95,7 @@ public static class Builder {
private String errorMessage;
private String errorReason;
private ErrorType errorType;
+ private Throwable cause;
/**
* Sets the error category for the ProgramFailureException.
@@ -148,13 +141,25 @@ public Builder withErrorType(ErrorType errorType) {
return this;
}
+ /**
+ * Sets the cause for the ProgramFailureException.
+ *
+ * @param cause the cause (which is saved for later retrieval by the getCause() method).
+ * @return The current Builder instance.
+ */
+ public Builder withCause(Throwable cause) {
+ this.cause = cause;
+ return this;
+ }
+
/**
* Builds and returns a new instance of ProgramFailureException.
*
* @return A new ProgramFailureException instance.
*/
public ProgramFailureException build() {
- return new ProgramFailureException(errorCategory, errorMessage, errorReason, errorType);
+ return new ProgramFailureException(errorCategory, errorMessage,
+ errorReason, errorType, cause);
}
}
}