I'm going to assume that there are situations where it is reasonable to throw exceptions.
I'm also going to assume that this is a situation where it is reasonable to use exceptions . (theThe fact that this is "internal" to your code does not alter this). And you cannot reasonably infer that exceptions are in appropriate based on the proposed exception name ... @Jarrod Roberson note!)
So the question is whether it is reasonable to declare a private exception class. To that I would say "yes""Yes", assuming that there is no existing exception class that is suitable.
The only riders I would make is that if there is any chance that the exception might "leak", then:
- you should declare a constructor so that the exception has a reason String, and
- you should declare it as
public... so that any javadoc for the exception appears in the published API documentation.