`

Guava 异常处理例子

 
阅读更多

 


Closer closer = Closer.create();
    try {
      InputStream in = closer.register(openInputStream());
      OutputStream out = closer.register(openOutputStream());
      // do stuff
    } catch (Throwable e) {
      // ensure that any checked exception types other than IOException that could be thrown are
      // provided here, e.g. throw closer.rethrow(e, CheckedException.class);
      throw closer.rethrow(e);
    } finally {
      closer.close();
    }

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics