Get rid of annoying checked exceptions!
Instead of:
try {
URL url = new URL("http://www.github.com");
// Other code you really don't want in this try-block
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}(or even worse, propagating the exception up your stack)
Just write:
import static com.github.nocatch.NoCatch.noCatch;
...
URL url = noCatch(() -> new URL("http://www.github.com"));And any checked exception will automatically be wrapped into a runtime exception (NoCatchException). Woa!
Gradle:
dependencies {
compile 'io.github.micheljung:nocatch:2.0'
}You can specify your own wrapper exception just like so:
// Throws WrapperException instead of NoCatchException
URL url = noCatch(() -> new URL(";"), WrapperException.class);Make sure your exception has a contructor like public WrapperException(Throwable cause).
Want to specify your own wrapper exception globally? No problem:
NoCatch.setDefaultWrapperException(RuntimeException.class);
// Throws RuntimeException
noCatch(() -> new URL(";"));