Skip to content

Latest commit

 

History

History
53 lines (45 loc) · 1.28 KB

README.md

File metadata and controls

53 lines (45 loc) · 1.28 KB

Description

uncheck is a very simple Java library aiming to ease the transformation of checked exceptions into runtime exceptions using lambda.

Without uncheck

Wrapping a checked exception inside a runtime exception usually requires some boilerplate code:

try {
    unsafeMethod();
} catch(Exception e) {
    throw new RuntimeException(e);
}

This can even be more verbose when the unsafe call returns a value to process:

Object result;
try {
    result = unsafeMethod();
} catch(Exception e) {
    throw new RuntimeException(e);
}

process(result);

With uncheck

Using uncheck, you can improve the readability of your code by removing the boilerplate part of it:

uncheck(this::unsafeMethod);

It also nicely handles methods returning values:

Object result = uncheck(this::unsafeMethod);
process(result);

Note

Caught exceptions are processed this way:

  • RuntimeException are just propagated as they are
  • IOException are wrapped inside UncheckedIOException
  • other exceptions are wrapped inside RuntimeException

Download

Just add the following dependency in your pom.xml:

<dependency>
    <groupId>com.github.ylegat</groupId>
    <artifactId>uncheck</artifactId>
    <version>1.0</version>
</dependency>