Is it a valid use case of using java.util.MissingResourceException? I have a factory method that returns an Object based on a argument passed to it :

public class Factory {
   private Map&lt;String,CustomObject&gt; objectMap;

   public CustomObject getObject(String key){
       if(objectMaps.containsKey(key)) return objectMap.get(key);
       throw new MissingResourceException("Object not found",CustomObject.class.getName(),key);
   }
}


I wanted an opinion on whether the use of java.util.MissingResourceException is valid. I don't want create a custom exception for above scenario. I want to use one of the existing ones. If possible which other existing exception can be used in above case. I was thinking of IllegalStateException,but it didn't seem the right choice.
This is easy to answer: The Exception does not belong to your problem domain. It is not "your" exception. So its use is not appropriate.

Another point to mention is: MissingResourceException is used when the code would expect a static resource provided by a deployment or packaging. Resource-files may be somthing like images or i18n-files. Furthermore configuration-files and everything that is expected to be available in a static way. So your use case does not match the proper usage either.

My suggestion is not to reuse java exceptions that have special usages within the java language unless you are working on the same "abstraction level". You should inherit your own exceptions from "Exception" or far better "RuntimeException" (not signature relevant) and match the exceptions to YOUR problem domain. Everything else is misleading and you have a hard time to identify the proper exception for YOUR context. I do not think that it even exists because of the different abstraction levels. JAVA Exceptions deal with the JAVA language semantics. Everything you do as a developer is nearly always on a higher abstraction level.

JAVA Documentation:

https://docs.oracle.com/javase/7/docs/api/java/util/MissingResourceException.html

https://docs.oracle.com/javase/7/docs/api/java/lang/IllegalStateException.html