I have a number of custom Exception
-inheriting classes in my package, which do not differ from their base class. The only purpose I have them is to distinguish one exception cause from the other, when it is thrown. This is how one of my Exception class looks like:
package com.XXX;
/**
* Thrown when query format is invalid.
*/
public class InvalidFormatException extends Exception {
/**
* Public ctor.
* @param m Supplementary message
*/
public InvalidFormatException(final String m) {
super(m);
}
}
The problem is that all classes are absolutely identical, like twins. The only thing which is different is their names. I don't like this situation, since it's an obvious code duplication. In other languages (like PHP, Python, etc.) I would declare these classes on-fly during runtime, but Java doesn't allow this, as well as I understand. Is there any workaround?