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
- Host: GitHub
- URL: https://github.com/cbrt-x/try-catch-wrapper
- Owner: cbrt-x
- License: mit
- Created: 2022-04-23T17:35:51.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-08-03T09:48:44.000Z (over 3 years ago)
- Last Synced: 2024-04-29T19:38:50.807Z (over 1 year ago)
- Topics: java, lambda-expressions, library, maven, try-catch, try-catch-finally, wrapper, wrapper-library
- Language: Java
- Homepage:
- Size: 38.1 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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();
```