java - Catch Exception from Method Reference -
I'm trying to cross a method reference that throws a check exception:
< Code> Files.list ((Paths.get ("/ some / path"))) Maps (files :: readAllLines).How can I manage this exception (to wrap the context of the method without any rules).
If you want to catch exceptions for a specific value in
.map If I try, I would not recommend a method reference instead of using a lambda:
files.list ((paths.get ("/ some / path"). Map Work with (someVal) -> {try {// do 'someVal'} (prior to your expansion) {// handle error}});
If you If you want to open the exception again, you can see the error reference through the box. You can do this manually:
using the exception to the last box yourself
gt; e = new box & lt; & gt; (); files (List. ((Path ("/ some / path")) map ((some val) - & gt; {try} {work with some '' some '') (pre-expansions) {// handle error e.setVar (former);}}); if (e.getVar ()! = Null) {throw e.getVar ();} square box & lt; T & gt; {private t var; Public Zero Set (T) {this.var = var;} Public T getVar () {return.var; }}
Comments
Post a Comment