I would like to have several custom errors in my code (extending RuntimeException), however it seems that I need to write out the same code each time - can this be done without so much repetition?
For example, in the following code, if I wanted to also make an underflow error, or maybe some more errors, would I have to copy & paste this code replacing 'OverflowError' with whatever I want the new exception to be called? Is there any way of making this 'dryer'?
class OverflowError extends RuntimeException {
private static final long serialVersionUID = 1L; //VS Code says I need it and I don't know what this line does, but that's another question for another day
public OverlowError(String message) {
super(message);
}
}
It seems that if I extend RuntimeException with no code inside, it doesn't inherit the constructor and therefore will not work because of unexpected arguments.