Tag: 终于可

抓住Throwable进行清理是否可以?

举个这样的例子: public List readThings(List files) throws IOException { ImmutableList.Builder things = ImmutableList.builder(); try { for (File file : files) { things.add(readThing(file)) } return things.build(); } catch (Throwable t) { for (CloseableThing thing : things.build()) { thing.close(); } throw t; } } 代码审查评论的出现是因为通常有一条规则不能捕获Throwable。 执行此类仅故障清理的旧模式是: public List readThings(List files) throws IOException { ImmutableList.Builder things = ImmutableList.builder(); boolean […]