Skip to content
/ uncheck Public

A Java library for easily wrapping check exceptions inside runtime exceptions

License

Notifications You must be signed in to change notification settings

ylegat/uncheck

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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>

About

A Java library for easily wrapping check exceptions inside runtime exceptions

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages