StreamUnthrower

Introduction: Exception in lambda expressions
More: Author   ReportBugs   
Tags:

Main thing - see class Unthrow.java

Lets you use checked exception in lambda expressions. One import and use!

import utils.stream.Unthrow;
...
    static class BlaBla {
        void method() throws IOException { ... }
        boolean isSomething() throws IOException { ... }
    }

    public void blablaDemo() {
        // :)
        getBlaBlaList().stream()
                .filter( blaBla -> Unthrow.wrap(() -> blaBla.isSomething()) )
                .forEach(blaBla -> Unthrow.wrapProc(() -> blaBla.method()) );
        // :(
        getBlaBlaList().stream()
                .filter( blaBla -> { try { return blaBla.isSomething(); } catch (Exception ex) { throw new RuntimeException(ex); } } )
                .forEach(blaBla -> { try { blaBla.method(); } catch (Exception ex) { throw new RuntimeException(ex); } } );
    }
...

Full Demo example of use.

Comparison examples of usage:

Features: -

  • it does not create new exceptions - re use existing
  • a minimum code
  • no substitution Stream, only the wrapper over the lambda

License

MIT

Free Software, Hell Yeah!

Apps
About Me
GitHub: Trinea
Facebook: Dev Tools