简体   繁体   English

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

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

I am implementing simple guava CacheLoader as it is stated here 我正在实现简单的番石榴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);

Does this mean that I should create my own exception class and throw it if the value is null or is there any better way to hande the situation? 这是否意味着我应该创建自己的异常类,如果值为null或有什么更好的方法来处理这种情况,则将其抛出?

You're allowed to throw whatever exception you want -- that can be something you made, or something built-in. 您可以抛出任何想要的异常-可以是您自己创建的,也可以是内置的。 There's no special rule for what exception is most appropriate for caches -- just use whatever exception would be most appropriate otherwise. 对于哪种异常最适合缓存并没有特殊的规则-可以使用其他最合适的异常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM