Guava CacheLoader 无法加载数据应该抛出什么异常?

What exception should be thrown when Guava CacheLoader is unable to load the data?

我正在实现简单的 guava CacheLoader,正如这里所述

   CacheLoader<Key, Graph> loader = new CacheLoader<Key, Graph>() {
     public Graph load(Key key) throws AnyException {
       return createExpensiveGraph(key);
     }
   };
   LoadingCache<Key, Graph> cache = CacheBuilder.newBuilder().build(loader);

这是否意味着我应该创建自己的异常 class 并在值为 null 时抛出它,或者是否有更好的方法来处理这种情况?

您可以抛出任何您想要的异常——可以是您创建的异常,也可以是内置的异常。对于哪种异常最适合缓存没有特别的规则——只要使用其他最合适的异常即可。