Pages

Wednesday, August 29, 2018

DDoS DoS Hack Tools

DDoS DoS Hack Tools



this question has answer here:

  • java 8: lambda-streams, filter method exception 12 answers

i have code below.

private static void readstreamwithjava8() { stream<string> lines = null; try { lines = files.lines(paths.get("b.txt"), standardcharsets.utf_8); lines.foreachordered(line -> process(line)); } catch (ioexception e) { e.printstacktrace(); } { if (lines != null) { lines.close(); } } } private static void process(string line) throws myexception { // process here throws myexception } 

here process(string line) method throws checked exception , im calling method within lambda. @ point need throw myexception readstreamwithjava8() method without throwing runtimeexception.

how can java8?

the short answer cant. because foreachordered takes consumer, , consumer.accept not declared throw exceptions.

the workaround like

list<myexception> caughtexceptions = new arraylist<>(); lines.foreachordered(line -> { try { process(line); } catch (myexception e) { caughtexceptions.add(e); } }); if (caughtexceptions.size() > 0) { throw caughtexceptions.get(0); } 

however, in these cases typically handle exception inside process method, or old-school way for-loops.



visit link download

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.