How to define custom exception class in Java, the easiest way?

No, you don’t “inherit” non-default constructors, you need to define the one taking a String in your class. Typically you use super(message) in your constructor to invoke your parent constructor. For example, like this:

public class MyException extends Exception {
    public MyException(String message) {
        super(message);
    }
}

Leave a Comment