Skip to content

SeregaLBN/StreamUnthrower

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 

StreamUnthrower

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!

About

Exception in lambda expressions

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages