This is a style question as 'technically' it doesn't matter what type of exception you throw; it could be a java.awt.FontFormatException
, javax.management.modelmbean.XMLParseException
or even just a standard java.lang.Throwable
with whatever extra info you put in it.
That being said, as others have suggested, it's probably a better choice to 'roll your own':
public class InvalidFormatting extends java.lang.Throwable
{
/** The underlying error of this instance */
public final static String Error = "An invalid format has been detected";
/** Create a new {@code InvalidFormatting} exception */
public InvalidFormatting() {
super(InvalidFormatting.Error);
}
/**
* Create a new {@code InvalidFormatting} exception with additional information
*
* @param additionalMsg The additional information to append
*/
public InvalidFormatting(String additionalMsg) {
super(InvalidFormatting.Error + "\n" + additionalMsg);
}
}
Then it can be used as such
throw new InvalidFormatting("here's some extra info");
Hope that can help.