Skip to content

Latest commit

 

History

History
47 lines (38 loc) · 800 Bytes

README.md

File metadata and controls

47 lines (38 loc) · 800 Bytes

Java Auto catch

Simplify try catch block

Maven

<dependency>
    <groupId>com.github.vgalloy</groupId>
    <artifactId>auto-catch</artifactId>
    <version>1.2.0</version>
</dependency>

Usage

Callable wrapping:

try {
    Thread.sleep(1_000);
} catch (final InterruptedException e) {
    throw new RuntimeException(e);
}

With Auto catch :

AutoCatch.autoCatch(() -> Thread.sleep(1_000));

Supplier wrapping:

final File file = new File("test");
final String canonicalName;
try {
    canonicalName = file.getCanonicalPath();
} catch (final IOException e) {
    throw new RuntimeException(e);
}

With Auto catch :

final File file = new File("test");
final String canonicalName = AutoCatch.autoCatch(file::getCanonicalPath);