safe call method function,and don't worry about exception throwing errors
This is a set of security wrapper classes. The error of the wrapped function will not affect the caller, and the underlying throwable can be consumed separately;
- 这是一套安全包装 Wrap 类,被 wrap 的函数报错不会影响到调用者,底层的 throwable 可以被单独消费
Maven:
<dependency>
<groupId>io.github.kubrickliu</groupId>
<artifactId>safe-call</artifactId>
<version>1.0.1</version>
</dependency>
SafeCall.wrap(() -> {
// do real method function
});
SafeCall.wrap(() -> {
// do real method function
}, {default_value}); // The second value is the default value in case of exception
SafeCall.wrap(() -> {
// do real method function
}, {default_value}, throwable -> {
// consumer throwable
});
SafeExec.wrap(() -> {
// do real method function
});
SafeExec.wrap(() -> {
// do real method function
}, throwable -> {
// consumer throwable
});