I am implementing custom Exception for Employee Service class. now want getter function for Exception class variables.
package com.sentienz.service.exception;
public class EmployeeServiceCustomException extends Exception {
private final int code;
private final String genericmessage;
public EmployeeServiceCustomException(int code, String genericmessage) {
super();
this.code = code;
this.genericmessage = genericmessage;
}
public EmployeeServiceCustomException(String message, Throwable cause, int code, String genericmessage) {
super(message, cause);
this.code = code;
this.genericmessage = genericmessage;
}
public EmployeeServiceCustomException(String message, int code, String genericmessage) {
super(message);
this.code = code;
this.genericmessage = genericmessage;
}
public EmployeeServiceCustomException(Throwable cause, int code, String genericmessage) {
super(cause);
this.code = code;
this.genericmessage = genericmessage;
}
public int getCode() {
return this.code;
}
public String getGenericmessage() {
return this.genericmessage;
}
}
Actually, I want this but I am not able to do this. is java exception class has all private variable or some other other reason for this problem.
public int getMessage() {
return this.message;
}
Throwablealready declaresgetMessage()with return typeString.intis not return type compatible withString.