You can see the configuration map from apache commons here . It does not implement Map , but has a similar interface with several Helper methods such as getString , getStringArray , getShort , etc.
With this implementation, you can use the setThrowExceptionOnMissing(boolean throwExceptionOnMissing) method and you can catch it and handle it setThrowExceptionOnMissing(boolean throwExceptionOnMissing) you want.
Not exactly with a custom message, but from my point of view it does not make sense to throw a fixed exception only with a custom message, since the type of exception itself depends on the context in which the get method is called. For example, if you are receiving a user, the exception will be associated with what perhaps UserNotFoundException , not just RuntimeException with the message: User not found on map!
Francisco spaeth
source share