I have a class that contains a cache (Set), and the cache is built on instantiation. I am confused which exception / error I should use if the building cache fails (it is not possible to connect to the database or to some).
class Provider { public Provider() { buildCache(); } private void buildCache() { try { this.cache = getDataFromDb(); } catch (Exception ex) { throw new ??? } } }
The only exception comes to my mind: ExceptionInInitializerError , but javadoc says it is initialized with static members.
Should I throw an IllegalStateException because the cache is not built, so this class is useless?
It is clear that I can create my own ErrorOnBuildingCache and throw it away, but I am wondering if any exception in the Java library is suitable for this circumstance.
source share