// concurrent/StreamExceptions.java// (c)2017 MindView LLC: see Copyright.txt// We make no guarantees that this code is fit for any purpose.// Visit http://OnJava8.com for more book information.import java.util.concurrent.*;import java.util.stream.*;public class StreamExceptions {static Stream<Breakable>test(String id, int failcount) {returnStream.of(new Breakable(id, failcount)).map(Breakable::work).map(Breakable::work).map(Breakable::work).map(Breakable::work);}public static void main(String[] args) {// No operations are even applied ...test("A", 1);test("B", 2);Stream<Breakable> c = test("C", 3);test("D", 4);test("E", 5);// ... until there's a terminal operation:System.out.println("Entering try");try {c.forEach(System.out::println); // [1]} catch(Exception e) {System.out.println(e.getMessage());}}}/* Output:Entering tryBreakable_C [2]Breakable_C [1]Throwing Exception for CBreakable_C failed*/
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。