An open API service indexing awesome lists of open source software.

https://github.com/cbrt-x/try-catch-wrapper

A wrapper for a Try-catch block in Java, providing useful methods to obtain values from the block
https://github.com/cbrt-x/try-catch-wrapper

java lambda-expressions library maven try-catch try-catch-finally wrapper wrapper-library

Last synced: 3 months ago
JSON representation

A wrapper for a Try-catch block in Java, providing useful methods to obtain values from the block

Awesome Lists containing this project

README

          

# Download via [Jitpack](https://jitpack.io/#Jadefalke2/Try-Catch-Wrapper/v1.0.0)
```xml


jitpack.io
https://jitpack.io

```
```xml

com.github.Jadefalke256
Try-Catch-Wrapper
v1.0.1

```
# Usage
### Run method
```java
Try.attempt(this::executeMethod)
.onCatch(Throwable::printStacktrace)
.run();
```
### Obtain value from method call
```java
var files = Try.attempt(() -> Files.list(path))
.onCatch(IOException.class, Throwable::printStacktrace)
.obtain();

files.ifPresent(this::doSomething);
```
### Use `finally`
```java
Try.attempt(this::startProcess)
.onFinally(this::endProcess);
.run();
```