0

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;
    }
1
  • 2
    The problem is that Throwable already declares getMessage() with return type String. int is not return type compatible with String. Commented Apr 8, 2018 at 19:44

1 Answer 1

2

There is no need to write your own getMessage since there is already one in the parent class Throwable.getMessage() - which you simply inherit anyway.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.